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

Android How to clear stack of an application if its open before launching by another appliction?

i am launching another application through my application,so i want to check is any instance of that application is already in stack or not? if exist then clear all instance before launch.
MR. Kumar
  • 661
  • 8
  • 25
1
vote
2 answers

Switching between two activities

Imagine that you have 2 activitie - A and B. You're starting B from A. In B you have a task. And if task is completed you want to go back to A when back key pressed if not you want to dismiss the whole application. But after dissmissing you can…
Lingviston
  • 5,479
  • 5
  • 35
  • 67
1
vote
1 answer

Launching Activity from BroadcastReceiver - dismissing it should not return to previous activity in my app's stack

Here's my scenario - the app starts with an Activity A which is the main launching point. There are various other activity that are launched from A, say B & C. Going from A to B should be reversible (pressing back actually returning), so every I…
Stephan Steiner
  • 1,043
  • 1
  • 9
  • 22
1
vote
1 answer

Handling Activity stack through application programmatically

I have four activities in my application A-->B-->C-->D. I write a My own class MyActivity which extends Activity class. I write this class to handle activity stack.This class has two methods addActivitiyTostack() and getActivityFromStack() I used a…
Ani
  • 1,611
  • 4
  • 14
  • 16
1
vote
1 answer

Changing Actiivity Stack Behavior

Well i have 2 activities, say A and B, user zipping between them like crazy A then going to B then A etc, now i dont want the normal behavior of zipping back to home through all those "layers" of A and B. I want that if the user is in A it will go…
Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
1
vote
2 answers

Open Browser as Intent but don't keep it on the Activity stack

I'm having some problems with understanding the activity stack and the behaviour of how it affects my app. Upon clicking a button it starts an Intent which opens the browser. When I'm in the Browser and I press the home button I land onto the…
methical
  • 132
  • 1
  • 7
1
vote
2 answers

Avoiding showing Previous Activities by overriding device back button

I havean Activity_A which has a Log-out option. On clicking that I call the Log-in Activity. So when i Click device back button when i am on Login-in Activity it takes me back to the Activity_A where i have the log-out option. what i wanted is, when…
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
1
vote
3 answers

popping a known number of activities from stack

in the process of building an app, I have an Activity lets call it A, and i open in multiple times, as A(1) -> A(2) -> A(3) -> ... -> A(m) -> ... -> A(n). In the app I want to pop all the way back to A(m), is there a way to pop activities all the…
thepoosh
  • 12,497
  • 15
  • 73
  • 132
0
votes
2 answers

Pop Activity From Stack onResume

When my program starts, it runs a mainActivity, which right away launches and loads data into another Activity. I do this because the data needs only be loaded once, in mainActivity, then sent along to the other activities! So! With that being…
Ethan Sherr
  • 413
  • 2
  • 5
  • 12
0
votes
2 answers

how to customize navigate stack on android

I have a situation like this I'm using a single activity but with different parameters so I assume that they are seperate activities This is a navigation sequence A-B-C-D-E-F, and in F I have a view that takes me to the C, or sometimes B. What I…
ikbal
  • 1,844
  • 4
  • 26
  • 46
0
votes
2 answers

Android back button new intent or finish()

I have a question. I have a list view (A) and a details view (B). On B, I have a "view list" button that will always take the user to the list. The thing is, I can get to B via a notification and not necessarily from A. So when clicking B, I can't…
guided1
  • 449
  • 5
  • 19
0
votes
0 answers

Restart App when in memory variable values are cleared

In the Android app, I have navigated as A->B->C->D When creating activity A, I store some values in static variables (as some form of in memory cache.) Then when moving to D, I use those values. When leaving the phone minimised for quite some time,…
0
votes
1 answer

Previous Activity does not come on pressing back button

I am calling one activity from another using following code. if(position==4) { Intent intent = new Intent(); intent.setClass(tlActivity, Income.class); startActivity(intent); finish(); } but when i am into the second activity which is…
0
votes
1 answer

React Native : MainActivity geting destroyed when app is put in background, when there is a second actitiy on top of it

Hi guy need some help! In my react native app, I'm starting a SecondActivity on top of the MainActivity, and when i put app in background from the second activity the MainActivity is getting destroyed and get removed from the Activity stack, so…
0
votes
2 answers

Android: Finish all activity and take user to home without loading home

There is home icon on app's app bar at top and I want to finish all activities and take user to home page. But, I don't want home page to be re-created. I have already tried following but it re-creates home page and I don't want it fun…
user1288005
  • 890
  • 2
  • 16
  • 36