Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Life cycle of Android Activity after pressing Back button

I am little confused between the life cycle of two activities.

Suppose I have Activity A and Activity B.

B is called From A i.e A ----> B.

Now currently B is on the screen and I pressed back button. Here I want know:- is there any memory still available for B(Active) or B's memory is flushed(Inactive).

like image 935
AJ. Avatar asked Feb 25 '14 10:02

AJ.


People also ask

What happens to activity when back button is pressed?

This is an override function called when the user presses the back button on an Android device. It has great implications on the activity lifecycle of the application. The official documentation states that onBackPressed() method is called when the activity has detected the user's press of the back key.

What is the life cycle of Android activity?

Activity-lifecycle concepts To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.

What is the first call back method during activity life cycle in Android?

1. onCreate(): In this state, the activity is created. 2. onStart(): This callback method is called when the activity becomes visible to the user.

When a user kills an activity by tapping the back button method is called?

If you hit the back button, then your Activity is finished and is destroyed, always resulting in a call to onDestroy().


3 Answers

Suppose there is an activity A, from which you launch activity B. If, while in activity B, you hit the back button, you are popping activity B off the stack and B will not be in the activity stack any longer.

Whenever you push an activity to the stack, onCreate is called, and if you press back button, onDestroy is called, which means that the activity is flushed away.

stack

Please visit my blog for further information: http://upadhyayjiteshandroid.blogspot.in/2013/02/android-lifecycle.html

activity lifecycle please visit for more

http://developer.android.com/guide/components/tasks-and-back-stack.html

http://developer.android.com/training/basics/activity-lifecycle/starting.html

like image 64
Jitesh Upadhyay Avatar answered Oct 07 '22 15:10

Jitesh Upadhyay


The following activity call back methods are called, after pressing back button.

onPause()
onStop()
onDestroy()

The activity is destroyed.

And it recreates when launched again. These are the callback methods when it launches again.

onCreate()
onStart()
onResume()
like image 21
Annada Avatar answered Oct 07 '22 13:10

Annada


I know the answer is been accepcted, still if this helps someone I am putting it.

When app is opening for the first time, by clicking the Icon

onCreate()
onStart()
onResume()

When home button is pressed

onPause()
onStop()

when app is again opened by clicking the app icon or launched from recent

onRestart()
onStart()
onResume()

when app is opened and then back button is pressed

onPause()
onStop()
onDestroy()
like image 15
DAS Avatar answered Oct 07 '22 13:10

DAS