Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android how long will our activity be there in the stack

My concern is, how long will our activity be there in the stack?

What I mean is, when the home button is pressed from my app and then my app is launched again by clicking its icon, it will regain the correct place from where I pressed the home button without writing any special code for this.
I don't know whether I'm right, I think that my app is pushed to a stack, and when I launched it, it's pulled from the server.
I want to know how long will be in that stack or any other place where it is stored? Will it be replaced by some other app after pressing the home button and using many other apps?

like image 449
Labeeb Panampullan Avatar asked Nov 13 '10 15:11

Labeeb Panampullan


2 Answers

Your activity will remain loaded until Android decides it needs the resources back. There are methods you can override in your activity to deal with this. Read more here.

Edit: See comment below for newer link.

like image 70
aptwebapps Avatar answered Sep 28 '22 02:09

aptwebapps


You should also see the documentation on the Android Activity Lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
and Process Lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle
http://www.edu4java.com/android_course/processes-and-threads.html#Lifecycle

There is a hierarchy of which activities will be killed first when Android needs to reclaim resources:

  1. empty processes (hosting no activities or other application components)
  2. background activities
  3. service process (running a service started with startService())
  4. visible activities (visible on screen but not in focus, such as one behind a dialog)
  5. foreground activity
like image 24
Mu Mind Avatar answered Sep 28 '22 00:09

Mu Mind