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
2 answers

Finish old instance of activity and start new instance of the same activity

I have MenuActivity with two buttons "New Game" and "Resume" with onClick methods newGame() and resume() respectively newGame() method starts GameActivity and finishes MenuActivity. resume() method. When resume(), MenuActivity finishes itself and…
Nazerke
  • 2,098
  • 7
  • 37
  • 57
2
votes
1 answer

implement behaviour similar to "don't keep activities"

There's a scenario in my app which it could go activity a->activity b->activity a->activity b...infinitely, and eventually it'll get OOM. Is anybody aware of a way to make it like the "don't keep activities" behaviour,e.g. the activities will be…
2
votes
4 answers

Android loading an activity stack, vs back button

what is the best practice regarding the back button currently? A lot of apps save and restore an entire activity stack when you open them (after they've been onStop and onDestroyed), take Facebook for example, when you open it and your last place…
CQM
  • 42,592
  • 75
  • 224
  • 366
2
votes
2 answers

updating the activity when the child activity close

I have an Activity stack like: activity A make something activity A call Activity B (without finish();) activity B make something activity B call activity C activity B finish(); activity C make something activity C finish(); i would like to…
2
votes
3 answers

what is the right way to clear background activity/activites from stack?

as the questions title says - I need to know what is the best way to "remove"/destroy/finish an activity that are somewhere in the middle of stack and currently on pause mode (not specific instances - but specific derived classes). for example: …
1
vote
1 answer

Make an activity root without clearing anything

Say, I have A->B->C->D stack. How can I rearrange it to D->A->B->C?
Eugene Chumak
  • 3,272
  • 7
  • 34
  • 52
1
vote
1 answer

Not adding a new Activity to the current Activity stack

I'm sure this has been covered but I can't find it anywhere, I basically have a launcher app that fires off to the market place when I select an item. When the user navigates away from the app though and then comes back to it can still show the…
gunboatmedia
  • 435
  • 1
  • 6
  • 15
1
vote
1 answer

Android - Activity stacks, bringing current activity to front and disabling back key

I have an application which has the following activities; Login -> Home Area -> Interaction recorder (touch screen to record interaction) Whilst this interaction recorder is active i want to be able to allow the user to exit the app through either…
Garbit
  • 5,805
  • 6
  • 39
  • 72
1
vote
0 answers

Android - Crash starting an activity from a service

I get the following crash on Firebase crashlytics and I have no idea what I can do to solve it. It happens very rarely. The scenario is that I start an activity from a service while the app is in the background. Any thoughts? It happens on Android…
Anonymous
  • 4,470
  • 3
  • 36
  • 67
1
vote
0 answers

Android: get top activity of the task before API 23

here's the question: MainActivity is a starting screen to launch activities A, B, C and so on. Before activity A is launched, it has to make some checks that take time, so a fast user can open activity B before activity A gets to the screen. If…
1
vote
2 answers

android new task and activity stack issue

I have my launcher activity (A) set to "singleTop". Now there is something in notification bar. User clicks on it. So I start activity in receiver with Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK So A's onNewIntent is invoked…
Rahul
  • 1,403
  • 4
  • 18
  • 31
1
vote
3 answers

Activity not running in background in android

When clicking on the home button and restarting the application again, it starts from the first screen rather than staying at the screen I left. Thanks for help. public class WelcomeScreen extends Activity implements OnClickListener { /** Called…
Kakey
  • 3,936
  • 5
  • 29
  • 45
1
vote
2 answers

Three Activity stacks

I'm trying to figure out how to implement an interesting concept. Suppose there's a bar at the bottom of my application with 3 buttons. We'll call them A, B, C. I want you to think of these as 3 areas of the app, each with their own Activity…
Andrew
  • 20,756
  • 32
  • 99
  • 177
1
vote
2 answers

Activities and sub activities

My Application has 5 different activities ( name them as A,B,C,D,E ) and there is a menu (made by buttons on bottom of the screen), to switch between A,B...E when I am displaying A, there are some button by which the user goes on another activity A1…
1
vote
2 answers

How can I clear activities stack when user tap on FCM notification message?

My android app receives FCM notifications messages (display messages) from web server. If the notification arrives while app is in background mode, and the user tap on it, a new "MainActivity" is launched on top of task stack. Then, when the user…