Possible Duplicate:
Android Activity Life Cycle - difference between onPause() and OnStop()
my question is about if it is possible to detect when an Android activity starts/ends.
The idea would be to have a listener o callback method to execute some code during those events, but I can't find anyone :_(
Thank you very much in advance for your help!!!
You can determine if the activity is finishing by user choice (user chooses to exit by pressing back for example) using isFinishing() in onDestroy . @Override protected void onDestroy() { super. onDestroy(); if (isFinishing()) { // wrap stuff up } else { //It's an orientation change. } }
Using activity. isFinishing() is the right one solution. it return true if activity is finished so before creating dialog check for the condition. if true then create and show dialog.
The android startActivityForResult method, requires a result from the second activity (activity to be invoked). In such case, we need to override the onActivityResult method that is invoked automatically when second activity returns result.
Checkout the android activity life cycle. You have hooks available to do custom tasks during the various life cycle events.
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