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
2
votes
1 answer

Is it normal for a fatal exception not to kill my entire Android Application?

I'm a little concerned that if I encounter an exception in one of my activities in my application the force close dialog seems to bring me back to a previous activity in the application history/stack instead of killing the whole application. Is this…
jason
  • 427
  • 5
  • 20
2
votes
3 answers

Clear activity stack before launching another activity

Hi there (my first question here ;-) There might be similar questions but none of them seem to answer my question or gives me a real solution... Problem A (root) starts B. B can start other activities. A decides to dismiss the stack (network…
Knickedi
  • 8,742
  • 3
  • 43
  • 45
2
votes
1 answer

How to send app to background after finishing activity which is started from push notification

I have an activity which is called if the app receives a push notification. The activity is started with FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TOP. The activity, let's call it 'A' shows UI and finishes after a while. In this point have a…
2
votes
3 answers

How to show activity from activity stack

i need some help about activity stack. In my app i have 6 screens user navigate from 1-->2-->3-->4--> when i go to 4 screen i have cancel button when user click on that button it should go to second screen and when user clicks back button on…
VK.Dev
  • 801
  • 4
  • 11
  • 24
2
votes
1 answer

How to remove Specific activity/activities from activity stack based on some action?

I am working on an application where i need to navigate to specific activity based on some actions. Here is a image Here my first activity is the ReadingActivity. Based on some actions user will be taken to the NewProjectReadingActivity. There the…
2
votes
2 answers

Launch activity from notification instantiating activity even if already there

My app has a background service which can run even if the app is destroyed. The app has two activities: A, which is the main activity, and B, a settings activity. The notification is created whenever the app goes to background. If I am in A, go to…
2
votes
1 answer

Delete specific stack activity

In my application I have a sequence of 5 activitys, which from the second, there is the restart button, this should go back to first, the problem is that the stack still holds, which creates a problem, since the user can click back. Clearing the…
Woton Sampaio
  • 469
  • 6
  • 24
2
votes
3 answers

Android launch an activity from a broadcast receiver

I know it may not be best practice but this is what i want to do. When my broadcast receiver is called - start a new activity which has is not fullscreen and has a transparent background - which opens on top of your current activity / desktop…
RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130
2
votes
2 answers

Keep the root activity even after starting new activity and clearing the back stack

I will be starting activities in the following series: A->B->C->D Now I want to start another activity suppose E from D and clear the stack but keep activity A as root activity. After starting E the stack should be A->E. How can I achieve this?
Aju
  • 4,597
  • 7
  • 35
  • 58
2
votes
4 answers

How to navigate forward between activities while discarding a login screen from the stack?

I have an app that if I am on a certain screen, and the user tries to access a specific part of the app that needs auth, it goes to the log in screen before continuing. What the app currently does is, say I am on screen 3, but want to go to screen…
Stillie
  • 2,647
  • 6
  • 28
  • 50
2
votes
1 answer

Android - Activity Stack/Tasks with Navigation Drawer

I have three top level activities in my application. Activity A, B & C. Each one of these activities hosts a navigation drawer. I am trying to figure out the best way to manage the activity stack between these three activities. For example, When I…
Nick H
  • 8,897
  • 9
  • 41
  • 64
2
votes
0 answers

What are TaskRecords in the dumpsys

I have the following activity stack from the dumpsys: Running activities (most recent first): TaskRecord{4307f828 #56 A com.demo.proj U 0} Run #4: ActivityRecord{425a6838 com.demo.proj/com.demo.proj.Activity2} Run #3: ActivityRecord{427dc860…
barq
  • 3,681
  • 4
  • 26
  • 39
2
votes
2 answers

When to use FLAG_ACTIVITY_RETAIN_IN_RECENTS?

I am trying to familiarize myself with intent flags, and I want to understand FLAG_ACTIVITY_RETAIN_IN_RECENTS. I have read the documentation and it seems like if this flag is set when calling an Activity, if the user presses the back button or that…
portfoliobuilder
  • 7,556
  • 14
  • 76
  • 136
2
votes
2 answers

Android TaskStackBuilder.startActivities() doesn't work as expected

Possible douplicate of Android - Build a notification, TaskStackBuilder.addParentStack not working Although there are a lot of questions answered about this topic but none of them solved my problem. I'm actually, playing with all of them but…
Hesam
  • 52,260
  • 74
  • 224
  • 365
2
votes
2 answers

TabWidget Activity Handling - Does it Create a New Activity EVERY Time?

When a TabWidget is using intents to designate the target Activity for each tab, is there any special handling of those Activities on the Activity Stack outside of the default operation? For Instance, if my app has tabs A, B, and C, and I click them…
stormin986
  • 7,672
  • 15
  • 42
  • 54
1 2
3
9 10