1
I’m not able to save the value obtained rewardItem mine to be displayed in a Textview, every time I close the application and return to the same value and 0. Can someone help me with this mistake?
This is my main activity code, where I try to save. if it is possible correct him 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);
}
}
Are you loading the value in Textview as soon as your Activity opens? By your code it seems that you only increase the value once a reward is received.
– regmoraes