Сохраняет только один раз, потом не прибавляется к переменной вообще
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
initializeLogic();
if(data.getString("money", "").equals("")) {
data.edit().putString("money", "0").commit();
}
else {
textview3.setText(data.getString("money", ""));
}
}
private void initialize() {
button3 = findViewById(R.id.button3);
button2 = findViewById(R.id.button2);
button1 = findViewById(R.id.button1);
linear1 = findViewById(R.id.linear1);
textview2 = findViewById(R.id.textview2);
textview3 = findViewById(R.id.textview3);
data = getSharedPreferences("IOExceptionMiningFer", Activity.MODE_PRIVATE);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RewardShow();
}
});
}
public void initializeLogic() {
MobileAds.initialize(MainActivity.this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
RewardLoad();
}
public void RewardLoad() {
AdRequest adRequest = new AdRequest.Builder().build();
RewardedAd.load(this, "ca-app-pub-3940256099942544/5224354917",
adRequest, new RewardedAdLoadCallback() {
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
// Handle the error.
mRewardedAd = null;
}
@Override
public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
mRewardedAd = rewardedAd;
}
});
}
public void RewardShow() {
if (mRewardedAd != null) {
Activity activityContext = MainActivity.this;
mRewardedAd.show(activityContext, new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
// Handle the reward.
btc += 2;
data.edit().putString("money", String.valueOf((long)(btc))).commit();
int rewardAmount = rewardItem.getAmount();
String rewardType = rewardItem.getType();
}
});
} else {
}
}
}