Android contradicting documentation about lifecycle callbacks onPause() and onStop() -
intuitively, applicable callback perform stuff in onpause()
. yet, there seems contradiction in documentation:
according https://developer.android.com/guide/components/activities/activity-lifecycle.html:
onpause() execution brief, , not afford enough time perform save operations. reason, you should not use onpause() save application or user data, make network calls, or execute database transactions; such work may not complete before method completes. instead, should perform heavy-load shutdown operations during onstop().
you should use onstop() perform relatively cpu-intensive shutdown operations. example, if can't find more opportune time save information database, might during onstop().
according https://developer.android.com/reference/android/app/activity.html:
note "killable" column in above table -- methods marked being killable, after method returns process hosting activity may killed system @ time without line of code being executed. because of this, should use onpause() method write persistent data (such user edits) storage.
so, should done , on spawned thread? how commonly done?
good catch!
some notes sum up:
- don't use
onpause()
"really heavy-load shutdown operations", otherwise risk negative user experience slowing down "next activity resumed until method returns." in other cases go it; - if still hesitate, use
onsaveinstancestate()
. it's called betweenonpause()
,onstop()
and, afaik, guaranteed called. system relies on method "so when activity has been killed, system can restore state coming in future"; - regarding
onstop()
, have never! experienced killing app's process until method returns, seen questions stating so, which, know, corresponds official documentation. but, it's rare. it's whether rely on or not.
Comments
Post a Comment