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

3 Activity stack situation

I am workig with android.developer Activity Stack demo app. The initial activity is called "A". From "A" you can start "B" and "C" activities. Essentially from any activity you can start the other two. Here is the situation that puzzles me: I start…
372
  • 237
  • 2
  • 10
0
votes
5 answers

Resuming activity from another activity

I have MenuActivity with "new game" and "resume" buttons. "new game" starts FireRoomActivity. public void newGame(View view){ Intent intent = new Intent(this, FireRoomActivity.class); this.finish(); startActivity(intent); …
Nazerke
  • 2,098
  • 7
  • 37
  • 57
0
votes
1 answer

Android remove multiple instances of same activity except the first

I saw many threads similar to this. But my scenario is different. This is my Activity flow Activity A -> Activity A (optional)('n' times) -> Activity B -> Activity C When I click a button in Activity C, I have to go back to First Activity A closing…
LoveMeSomeFood
  • 3,137
  • 7
  • 30
  • 53
0
votes
1 answer

How to control which activity is loaded from launcher when app is already running

I have an application with multiple activities. The first one is a login/startup activity followed by a few that change during the lifetime of the application (and its "logged in" connection). If the user presses the home button, it returns to the…
BJV
  • 1,133
  • 8
  • 15
0
votes
1 answer

Android Activity Task in foreground

I have 3 activity tasks A-B-C
Vacxe
  • 91
  • 5
0
votes
1 answer

Activity stack is not clearing after giving Cleartop

I am having 4 buttons at the bottom. Suppose A,B,C,D. These buttons I have created as a widget and including in every layouts. ON each button click I am opening one activity which I have implemented in Common class. When my application starts A will…
Aju
  • 4,597
  • 7
  • 35
  • 58
0
votes
1 answer

Clear activity stack in android

I have a LoginActivity as my launcher screen. And SettingsActivity as my fifth screen. I have a logout button in settings screen. On clcik of this button, how can i go to Screen-1 (i.e LoginActivity) by clearing all remaining activities (i.e 2nd,…
user1670443
  • 461
  • 2
  • 6
  • 17
0
votes
1 answer

Returning to the first activity in the activity stack without calling it explicitly

I'm developing an app which consists of two library projects. Both library projects are used by the actual app. The first library project can be seen as the main library project as it contains the main menu in form of a dashboard for the whole app.…
Flo
  • 27,355
  • 15
  • 87
  • 125
0
votes
4 answers

How can I return to my main activity from another activity that is more than one away in the stack?

I have a main menu activity with a bunch of buttons. One button starts a new activity that allows the user to fill out and submit a form. When the user submits the form, a third activity starts, basically just a screen with some content and a…
0
votes
1 answer

How to clear activity from activity stack that has been started from outside the activity in android?

I have a broadcast receiver class that starts some dialog activity say A with the intent flag Intent.FLAG_ACTIVITY_NEW_TASK as i am starting activity from outside Activity(Even when my app is not running) and everyone do the same. ** case : ** i…
Krishna Shrestha
  • 1,662
  • 14
  • 38
-1
votes
1 answer

how to get current activity from stack activity in Android

I want to get current activity from activity stack and replace with ?????? dialog =new AlertDialog.Builder(??????,android.R.style.Theme_Material_Dialog_Alert).setTitle("Tittle").setMessage("Message");` How Can I Do it? Update1 : I can't use…
Amir133
  • 2,372
  • 2
  • 18
  • 34
-1
votes
1 answer

Android handling click on notification

I have this situation in my app: I have these activities
Apperside
  • 3,542
  • 2
  • 38
  • 65
-1
votes
1 answer

Bring specific Activity in back stack to foreground and clear top

I have hybrid app where every page is loaded inside a WebPageActivity(webView). I don't want to create a new activity for every screen but create multiple instances of same activity for each hybrid html page. Following is the requirement, Navigation…
JTeam
  • 1,455
  • 1
  • 11
  • 16
-1
votes
1 answer

How to close previous activities when activity launch by intent-filter happens?

I have an Activity, that launches from browser by this intent-flter:
Lester
  • 2,544
  • 4
  • 27
  • 38
-2
votes
2 answers

Go back to previous activity

I have a page product to which overtime u press a button a different id is sent through intent.There is a buy button in this page if we are not logged in it will take us to login page so after I login how to I go back to this page with the same id…
Ciddarth Raaj
  • 55
  • 1
  • 6
1 2 3
9
10