android - When to commit application settings to SharedPreferences (onStop or onDestroy) -



android - When to commit application settings to SharedPreferences (onStop or onDestroy) -

i wondering, when suitable time save our application settings sharedpreferences. should during onstop, or ondestroy? realize both methods have pros , cons.

onstop

if user intention not quitting application, save application settings sharedpreferences seem redundant. simply press home (onstop called) -> long press home -> relaunch application select application again

ondestroy

user can kill application press home (onstop called) -> long press home -> swipe left on application kill it. if user quit application way, realize ondestroy not beingness called although app killed. hence, application settings not beingness saved.

so, improve save application settings, during onstop or ondestroy?

it best phone call commit() either right after you've made changes, or in onpause() method. ensures changes saved in pretty much every scenario, except uncaught exceptions crash app.

also, should note neither onstop() or ondestroy() guaranteed called @ all, particularly in situations when android low on memory. however, onpause() called.

android

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -