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

Proper way to add Activity under the top Activity

So I have a main activity, a disclaimer activity, and an update activity. The latter two are both added from the main activity. The update activity gets kicked off after it pulls down some data to see if it needs to update. So essentially what…
mouser58907
  • 797
  • 2
  • 10
  • 21
0
votes
1 answer

Update changes made to Activity from different Screens (Activity Stacking)

In my application I have Activities that effect other ones. An example is on the profile page changing the name or other data. When I am done making changes I click the save button which finishes the application and the profile screen is shown…
NVA
  • 1,662
  • 5
  • 17
  • 24
0
votes
2 answers

Activity stack or task for my application

I am using ActivityGroup in my application, structure is as follow A > B > C (where A display first), and B and C makes a loop, like B > C > B > C > B and at both B and C if a user press back button, activity A should be display(even if user is on…
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
0
votes
1 answer

Open Activity from Notification click when app is killed?

I am implementing calling functionality in my application with Twilio SDK. I am showing notification as soon as call starts, so the user can hang up the call from the notification bar. The problem is if user kills my application forcefully, I am not…
0
votes
2 answers

Activity stack not working as it is supposed to

I have an app which has a MainActivity. If its first launch, it launches an activity which displays a intro slider and if its not, it launches a MainWeatherActivity. Here is the code from the MainActivity @Override protected void…
Sriram R
  • 2,109
  • 3
  • 23
  • 40
0
votes
2 answers

android: Moving through activities without popping them

I have the following I wish to achieve: Activity A -> Activity B Activity B -> Activity A On paper it sounds like the same thing as just hitting the back button. Problem is, I don't want Activity B to be popped. I need something along the lines of…
Alex
  • 3
  • 1
0
votes
2 answers

Android - How to get last foreground activity on android?

I have an app which open different activity on different situation from response of server. Let i have two activity Activity A & Activity B. A or B can't be start at the same time. Let assume A activity is called to start and at the same time B is…
Md. Sulayman
  • 781
  • 8
  • 30
0
votes
3 answers

Clear activity navigation back stack

I am trying to implement block functionality in my app. There is only one activity that allows the user to block others. However this activity can be accessed using 4 different flow. Use Case: When a user is blocked the back stack needs to be…
Rajas47Ashtikar
  • 583
  • 2
  • 6
  • 11
0
votes
1 answer

Possible memory leak (Android, Glide, Activity stack)

I am facing a very common and nasty problem as OutOfMemory exception. To introduce my APP, it is heavy picture content one. And I discovered, I receive a OOM at 256mb in my device (Xiaomi 5s). I cannot find the memory leak (tried…
Aurimas Deimantas
  • 671
  • 1
  • 10
  • 29
0
votes
2 answers

How to manage Activity instances in Android

I have an initial activity O and one more activity A in which i can select to go to activities A1,A2,A3 and for example fill in a form in each of them. So i follow this path: O>A>A1>A>A2>A>A3 While i am at A3 i want to press the back button and go…
mike_x_
  • 1,900
  • 3
  • 35
  • 69
0
votes
5 answers

onBackPressed() should call previous activity's onBackPressed()

So here is the problem, I perform A → B and from B I do B → C , now when the back button is pressed in C I want to go back to A. so at start the flow is A → B → C but I want to clear B when I start C so when back pressed from C I go back to A. I…
Astronautilus
  • 83
  • 1
  • 9
0
votes
3 answers

Best way to handle activity state

I'm making an app that shows another activity when I correctly login however in the home screen when I pressed back and then returned to the app the login activity showed. I was able to avoid this overriding the onBackPressed this way: public void…
ALopez
  • 121
  • 1
  • 13
0
votes
4 answers

Activity in background gets killed when Home button is pressed

I encountered strange problem, lets say I have two activities A and B, app starts with Activity A, I proceed to activity B press Android Home Button, return to app which brings me back to Activity B. Then I press Back button (either hardware on in…
TheJudge
  • 576
  • 1
  • 9
  • 30
0
votes
0 answers

While in Service, check if there is a particular activity in Activity Stack

I need some advice for my application structure. It's about messaging using GCM. So I get onMessageReceived call in GcmListenerService (with message data). Now there are two cases: a) There already is a chat activity in Activity Stack and I should…
T.Vert
  • 279
  • 2
  • 13
0
votes
3 answers

How to clear current activity stack when start another activity which belong to another stack

For example:A start B, B start C, A and C belongs to 'Hello'-stack, and B belongs to 'World'-stack, when user press back button in Activity C, it will return to A. Note1:B means a lot of activities , not just one activity, like A start B1,B1 start…
empty-yo
  • 143
  • 1
  • 2
  • 6