I am not able to save the rewardItem value obtained from my to be displayed in a TextView, every time I close the application and return the same value and 0. Can anyone help me with this error?
This is my main activity code, where I try to save. if it is possible, correct it for me ...
@Override
public void onRewarded(RewardItem rewardItem)
{
addCoins(rewardItem.getAmount());
SharedPreferences sps = getSharedPreferences("save_coins", AppCompatActivity.MODE_PRIVATE);
SharedPreferences.Editor editor = sps.edit();
editor.putInt("my_coins", mCoinCount);
editor.commit();
}
@Override
public void onRewardedVideoAdLeftApplication()
{
}
@Override
public void onRewardedVideoAdFailedToLoad(int i)
{
}
private void addCoins(int coins) {
mCoinCount = mCoinCount + coins;
SharedPreferences spg = getSharedPreferences("save_coins", AppCompatActivity.MODE_PRIVATE);
int mCoinCount = spg.getInt("my_coins", 0);
mCoinCountText.setText("Coins: " + mCoinCount);
}
}