Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect when an Android activity starts and ends [duplicate]

Tags:

android

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!!!

like image 959
pedromateo Avatar asked Jun 09 '11 08:06

pedromateo


People also ask

How do I know if my android activity is recreated?

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. } }

How do you check if activity is finish or not?

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.

Which 2 methods do we override when we need to get a result from an activity started from an intent?

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.


1 Answers

Checkout the android activity life cycle. You have hooks available to do custom tasks during the various life cycle events.

like image 195
Kalarani Avatar answered Oct 27 '22 01:10

Kalarani