Where in onStart()
, onStop()
, onDestroy()
of an activity do I call super.onStart()
, super.onStop()
, super.onDestroy()
?
Answer: onPause() and onStop() will not be invoked if finish() is called from within the onCreate() method. This might occur, for example, if you detect an error during onCreate() and call finish() as a result. In such a case, though, any cleanup you expected to be done in onPause() and onStop() will not be executed.
OnDestroy will be called directly from any call to finish() in onCreate, skipping over onStop. onDestroy can be left out after a kill when onStop returns. Starting with Honeycomb, an application is not in the killable state until its onStop() has returned; pre-honeycomb onPause was the killable state.
onStart() is called when activity resumes from stopped state. For example, if you have activity A and starts activity B from it, then activity A will be paused ( onPause() ) and then stopped ( onStop() ) and moved to back stack.
onStop() Called when the activity is no longer visible to the user. Either because another Activity has resumed, and is covering this one, an existing activity is coming to the foreground, or the activity is about to be destroyed.
That's my way of calling these super methods:
OnCreate()
: Definitely the first thing.OnDestroy()
: The last thing.OnStop()
: The last thing.However, for the last two, no matter where you call them (in most most cases). So some people prefer to put them at the first to be consistent.
I would call super in the begining, I would probably have the base class complete its work before I do the work of the derived, like the rule in Java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With