Questions tagged [activity-stack]

Activities can open other activities. Each opened Activity is put on top of the opener. This stack is called BackStack in Android. You can navigate to the previous Activity by pressing the device's back button.

An application usually contains multiple activities. Each activity should be designed around a specific kind of action the user can perform and can start other activities. For example, an email application might have one activity to show a list of new email. When the user selects an email, a new activity opens to view that email.

An activity can even start activities that exist in other applications on the device. For example, if your application wants to send an email, you can define an intent to perform a "send" action and include some data, such as an email address and a message. An activity from another application that declares itself to handle this kind of intent then opens. In this case, the intent is to send an email, so an email application's "compose" activity starts (if multiple activities support the same intent, then the system lets the user select which one to use). When the email is sent, your activity resumes and it seems as if the email activity was part of your application. Even though the activities may be from different applications, Android maintains this seamless user experience by keeping both activities in the same task.

A task is a collection of activities that users interact with when performing a certain job. The activities are arranged in a stack (the "back stack"), in the order in which each activity is opened.

The device Home screen is the starting place for most tasks. When the user touches an icon in the application launcher (or a shortcut on the Home screen), that application's task comes to the foreground. If no task exists for the application (the application has not been used recently), then a new task is created and the "main" activity for that application opens as the root activity in the stack.

When the current activity starts another, the new activity is pushed on the top of the stack and takes focus. The previous activity remains in the stack, but is stopped. When an activity stops, the system retains the current state of its user interface. When the user presses the Back button, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored). Activities in the stack are never rearranged, only pushed and popped from the stack—pushed onto the stack when started by the current activity and popped off when the user leaves it using the Back button. As such, the back stack operates as a "last in, first out" object structure.

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

137 questions
5
votes
1 answer

onActivityResult and FLAG_ACTIVITY_NEW_TASK: workaround?

Here is my scenario: I have a series of Activity. I set a timeout on those Activity that will disconnect the user in case it get inactive for a moment. But I want to redirect the user to its last screen in case he log When I'm disconnecting the user…
MHogge
  • 5,408
  • 15
  • 61
  • 104
5
votes
2 answers

Android activity stack size problems?

I have an application with lots of activities. Many of these activities can start others, so the user's expected to generate a quite large activity stack. I'm currently using the default activity launch behaviours. Does anybody know, if a large…
Zsombor Erdődy-Nagy
  • 16,864
  • 16
  • 76
  • 101
4
votes
1 answer

Android SingleTask, SingleTop and Home Button

In my application there is a behavior that I don't understand. I have the MainActivity A as SingleTask. It calls an Activity B that is SingleTask too. When I press the Home button in the second activity to open another application, and after that I…
Igor
  • 222
  • 4
  • 14
4
votes
4 answers

Remove an activity from stack in android

I want to remove an activity from stack using code.Heres my case From page A I am going to page B. From page B i have to return to page A using return button. In page B I am having a button which takes to page C. When I click that button in page…
Zach
  • 9,989
  • 19
  • 70
  • 107
4
votes
1 answer

Android: how to return to Activity with "noHistory" attribute after onStop?

I was looking for a way to delete a certain activity from history stack, and found a solution here (Wakkas's anwer). However, if I close the app with this activity opened e.g. by pressing the home button, and later return to it, the activity is not…
jellyfish
  • 7,868
  • 11
  • 37
  • 49
4
votes
2 answers

Understanding android:launchMode

I'm getting really confused about the different activity launchModes in Android. I understand it has something to do with the activity stack which is also something not so clear to me. I would appreciate a short explanation about each launchMode…
smichak
  • 4,716
  • 3
  • 35
  • 47
4
votes
3 answers

Intent.FLAG_ACTIVITY_CLEAR_TOP is not working in Android

Hi I am developing android application in which I have activity flow like this A-->B-->C. So my intention is that as soon as B opens activity C close both A and B. For that I am trying to use 2 flags: Intent.FLAG_ACTIVITY_CLEAR_TOP and…
nilkash
  • 7,408
  • 32
  • 99
  • 176
3
votes
3 answers

Returning to an activity even though it has noHistory=true

I need to know if the following flow is normal: Activity A onPause is called because activity B took the focus, but a few seconds later, when activity B is finished and before onStop & onDestroy of Activity A were called, Activity A (same instance)…
galbarm
  • 2,441
  • 3
  • 32
  • 52
3
votes
1 answer

Android getParent() is null but parentActivityName is set

I have a child activity that updates the database, which is shown in a table below in the parent activity. When the parent activity (Update) is done, a commit is send to the database and the data will be updated. Afterwards I would like to close…
Vulkanos
  • 193
  • 19
3
votes
1 answer

Multiple activities with singleTask

I'm getting extremely confused with activity launch modes. Here is the scenario. Activity A - main, launcher with singleTask launch mode Activity B - singleTask launch mode Activity C - standard launch mode Now here is what I'm doing Activity A…
3
votes
2 answers

Android restore UI state on home button pressed?

I've two activities, A and B. My app goes from A to B. (A -> B). When I'm on B and press the back button (hardware back button) the state and UI of A is restored successfully (onResume() is being called). The problem is, when I press the home button…
Eric
  • 488
  • 4
  • 16
3
votes
2 answers

Back button takes me to launcher activity not deep-linker activity

Following procedure: Start my application, Stack: [HomeActivity] Going to Facebook, using a deep link to get into Activity X Pressing back button results in getting back to HomeActivity instead of Facebook Expected Start my application, Stack:…
3
votes
1 answer

taskstackbuilder for api 14

My compiler show this message... Call required API level 16 (current min is 14) The question is.. "Is this code is okay to run in api 14 or not??" because I have no device to test this API version since AVD doesn't have GPS (Requirement) Do I have…
Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96
3
votes
4 answers

android parent activity killed on startActivity

I have a simple application with a listview. When a user taps on a list item, i start a new activity Intent eventdetails = new Intent(HomeActivity.this,EventDetailsActivity.class); eventdetails.putExtra("eventId",…
Sameer S
  • 33
  • 1
  • 3
3
votes
2 answers

Back button restarts activity in stead of going back

I have a bug in my application I can't figure out. There are three activities: HomeActivity - A, TestActivity - B and ResultActivity - C. Activity A launches B in a normal way Intent intent = new Intent(this,…
Jørgen R
  • 10,568
  • 7
  • 42
  • 59
1
2
3
9 10