After watching a rewarded ad video, a text view displays the rewarded points. The points accumulate after each video. However, when the app closes, the points get erased. I would like the points to continue to show when the user comes back to the application. I could not figure out if this is part of the onDestroy method or savedinstance.
public class ProfileActivity extends AppCompatActivity implements RewardedVideoAdListener {
TextView mText, userEmail;
private int pointCount;
private TextView dateTimeDisplay;
private Calendar calendar;
private SimpleDateFormat dateFormat;
private String date;
Button userLogout;
Button goToHome;
ImageView ivQR;
private AdView mAdView;
FirebaseAuth firebaseAuth;
FirebaseUser firebaseUser;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
private RewardedVideoAd mRewardedVideoAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
//rewards ads
//ca-app-pub-9125010107042455/6647636731 actual
//ca-app-pub-3940256099942544~3347511713 for testing
MobileAds.initialize(getApplicationContext(), ("ca-app-pub-9125010107042455/6647636731"));
// Use an activity context to get the rewarded video instance.
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
//points count
mText = findViewById(R.id.textView);
pointCount = 0;
mText.setText("Points: " + pointCount);
loadRewardedVideoAd();
private void loadRewardedVideoAd (){
if (!mRewardedVideoAd.isLoaded()){
//ca-app-pub-9125010107042455/6647636731 actual
//ca-app-pub-3940256099942544/5224354917 for testing
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",new AdRequest.Builder().build());
}
}
public void startVideoAd(View view){
if(mRewardedVideoAd.isLoaded()){
mRewardedVideoAd.show();
}
}
@Override
public void onRewardedVideoAdLoaded() {
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}
private void addPoints(int points) {
pointCount += points;
mText.setText("Points: " + pointCount);
}
@Override
public void onRewarded(RewardItem rewardItem) {
Toast.makeText(ProfileActivity.this, " Points ", Toast.LENGTH_SHORT).show();
addPoints(rewardItem.getAmount());
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
@Override
protected void onPause() {
mRewardedVideoAd.pause(this);
super.onPause();
}
@Override
protected void onResume() {
mRewardedVideoAd.resume(this);
super.onResume();
}
@Override
protected void onDestroy() {
mRewardedVideoAd.destroy(this);
super.onDestroy();
}
@Override
public void onRewardedVideoCompleted() {
}
}