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

How to resume activity when application relaunched from android launcher?

I have an application that implements two activities. Activity A is for selecting some files on device and activity B is to show additional info while these files are processing. Both of them have singleInstance as launch mode. On application's…
0
votes
0 answers

Maintaining Single Variable[APP_MODE] for Different Activity stacks in a single application

I am working on an application where i have 3 launcher Splash Activities and as soon as its gets installed, its shows three launcher icons(for three activities). Now since each activity starts on a different Activity stack and the rest Code is…
0
votes
0 answers

Go back to previous acitivity stack after pressing Home in Android launcher

I am developing a custom launcher/home-screen, thus I am able to hand home-press events. Sometimes I want it to intercept Home-presses without affecting the visible activity-stack so to speak. When I press home, however, I get to the launcher stack…
JohnyTex
  • 3,323
  • 5
  • 29
  • 52
0
votes
1 answer

2 Activities get notified on GPS Status Changed

I have A Activity and B Activity, both implement LocationListener. So both have @Override public void onProviderDisabled(String provider) { // Open AlertDialog } I start B Activity from A Activity. When i turn off GPS on B, it opens…
0
votes
2 answers

Android: How to clear all activities in previous stack apart from the first activity

I have list of activities stack as a form but once the form finished I wanted to clear all the stack apart from the first activity but display a new activity so when clicking back on new activity will go back to the first activity. E.g. A -> B -> C…
LittleFunny
  • 8,155
  • 15
  • 87
  • 198
0
votes
2 answers

android activity stack- back navigation

I am developing an app which has a home screen consisting of list view(Home Activity).User clicks on list item and new activity is started named as Topic.This activity also consist of list view. Home is set as parent activity for Topic. Now in Topic…
0
votes
1 answer

Previous theme is shown after changing in prefs (Activity-Stack?)

my app has a really weird issue: In a PreferenceActivity I provide under a (Sub)PreferenceScreen a ListPreference where the user selects "light" or "dark". So I set up a OnPreferenceChangedListener and when the user triggers it, I will recreate…
Martin Pfeffer
  • 12,471
  • 9
  • 59
  • 68
0
votes
1 answer

launching more than one activity in android wear

Can we launch more than one activity in android wear micro app? I mean is it possible to have more than one activity in android wear activity stack? I tried launching 2 activities, but it threw an out of memory exception.
Sathish
  • 109
  • 1
  • 4
0
votes
3 answers

Clear ALL activities in back stack

I have this stack: Login Activity -> Registration Activity After a successful registration I call this: Intent i = new Intent(getApplicationContext(),Home.class); i.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK…
Nicolas Durán
  • 292
  • 8
  • 19
0
votes
2 answers

Android, what is more efficient? Hide activity or start new with old data

Hi I am developing the chat app for android (just private project) User has contact list in which he can choose the contact(lets call this activity contact_activity). When he chooses contact, next activity (lets call it chat_activity) opens and…
Smarty77
  • 1,208
  • 3
  • 15
  • 30
0
votes
5 answers

start second activity and fail to back to first activity

Assume that I completely quite my application. (no more activity stack) However, the notification arrive and user will be navigate to second activity when click The question is how can I make an second activity back to first activity (lancher) and…
Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96
0
votes
1 answer

Android - How to get Activity path

How can i get the path the end user takes to arrive at any activity. so if user visited Activities A, B , C .. then in Activity c i would be able to get a info like this "A/B/C". And likewise if user took the path directly to D, F then in…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0
votes
3 answers

Android - know what page level (hierarchy) your at on the activity stack

Starting from the Launcher activity i need a way to know what level (hierarchy) the app is at. For example image the user is in a shopping app & takes the following path: Main Activity ---> 2. list of shoes to buy ----> 3. shopping cart ---> 4.…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0
votes
1 answer

How to start activity twice with different layout and not keep it in activity back stack in Android

I have activities flow: +--+ +--+ +----+ |A1|-->|A2|-->|Home| +--+ +--+ +----+ BACK button in A1 and Home should close the app. So I call finish() on A1 when A2 is started and also on A2 when Home is started (thanks to that A1 and A2 are…
Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103
0
votes
1 answer

Android - Notification Pending Intent - Add to top of activity stack issue

I'm a bit confused with pending intents in the notification builder. I've got a MainActivity activity and a MessageList activity. I have a service to show a notification when a new message in found, and I want it to be that if the user presses the…
Shmuel
  • 3,916
  • 2
  • 27
  • 45