java - Sharing preferences in Android -
i want save values sharedpreferences in app. these values change when active (for example every game brings coins, , want save these coins). don't know when user quit app in order save coins next time. in every activity coins change have:
@override protected void onstop() { super.onstop(); sharedpreferences sp = getsharedpreferences("my_pref", activity.mode_private); sharedpreferences.editor editor = sp.edit(); editor.putint("coins", mainactivity.coins); editor.commit(); }
is there way better.
use isfinishing() in onpause() method means application paused , if isfinishing() true app end
@override protected void onpause() { super.onpause(); if(isfinishing()) { //finishing logic here } }
Comments
Post a Comment