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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -