which method
is called in current activity
when moving to another activity
? Let's take i am in Activity A
, from A i move to Activity B
.
I want to execute a particular piece of code
while moving to Activity B
which method
is called in current activity
when moving to another activity
? Let's take i am in Activity A
, from A i move to Activity B
.
I want to execute a particular piece of code
while moving to Activity B
Nothing is called on your current activity specifically for "moving to another activity".
Your current activity will be called with onPause()
when it leaves the foreground from an input standpoint, and it will be called with onStop()
when it is no longer visible. However, those will be called for any trigger for those events, including the user pressing HOME or BACK.
onPause and probably onStop (if the new activity takes up the entire screen) will be called on A. onDestroy 'can' be called at this point, but the system will keep it alive if it can.
onCreate, onStart, onResume will be called on B, unless B is already in the stack and you either use some flags in the intent, or B has a special launchMode, in which case, rather than onCreate, onNewIntent will be called.
onPause()
method is calledwhen it leaves the foreground and onStop()
method is called when the activity is no longer visible.. Also refer to the complete activity life cycle in the below mentioned link
Refer to table 1 of the activity life cycle in this link Activity Life cycle
onPause() and then onStop() methods will call when you change the activity ,,if you finish the current activity while moving to the second activity the onDestory() also called..
Here is an intrusting issue that if you start an your new activity in onStop method the onPause and onStop method wont call again :)