android - How Onstop Method work for this demo? -
i making demo understand stack , activity life-cycle.
i made:
mainactivity mainactivitydialog (another activity theme dialog) bactivityi launched app , main activity shown. press button show dialog, mainactivitydialog opened. 1 time again press button on mainactivitydialog bactivity opened. finally, pressed button.
mainactivity -> mainactivitydialog -> bactivity ---back---> mainactivitydialog
here log of app :
my question are:
why mainactivity stopped after launching bactivity mainactivitydialog? after bactivity lifecycle method called, why mainactivitydialog stopped?
after pressing button in bactivity, mainactivity starts first mainactivitydialog starts , mainactivitydialog resume?
the order of calls onstop()
, ondestroy()
on multiple activities indeterminate.
if have multiple activities in activity stack no longer visible on screen, android may phone call onstop()
on them whenever wants , in whatever order wants to. indication activity no longer visible user. cannot rely on order of onstop()
calls multiple activities.
the same goes ondestroy()
. android may phone call ondestroy()
on activity 1 time activity has finished. if have multiple finished activities in task, android may phone call ondestroy()
on them whenever wants , in whatever order wants to. indeterminate. phone call ondestroy()
inform activity no longer active , should release resources may have.
there no guarantee onstop()
or ondestroy()
ever called. lastly lifecycle phone call guaranteed onpause()
. after that, android can kill process without calling farther lifecycle methods.
in sec question want know why, after user presses button on bactivity
, mainactivity
starts first followed mainactivitydialog
. reason mainactivity
visible on screen first , mainactivitydialog
visible on screen on top of mainactivity
(because mainactivitydialog
dialog-themed, doesn't cover entire screen , can see parts of mainactivity
underneath it).
android android-activity android-lifecycle
No comments:
Post a Comment