Android – While switching between two activities, the calling order of lifecycle methods of Activity

Suppose There are two activities FirstActivity and SecondActivity.

Then this order will always remain same everytime.

// when you start FirstActivity

(1) OnCreate() -> OnStart() -> OnResume() of FirstActivity will be called

when you start SecondActivity using
startActivity(new Intent(FirstActivity.this, SecondActivity.class))

(2) OnPause() of FirstActivity will be called and then

(3) OnCreate() -> OnStart() -> OnResume() of SecondActivity will be Called then

(4) OnStop() of FirstActivity will be called

// when you press back button on SecondActivity

(5) OnPause() of SecondActivity will be called then

(6) OnRestart() -> OnStart() -> OnResume() of FirstActivity will be called then

(7) onStop() -> onDestroy() of SecondActivity will be called

 Note: 

 (1) OnPause() will be called first when you navigate to any other activity.
 
 (2) OnStop() will be called when activity is no longer Visible on screen.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)