Questions tagged [back-stack]

"Back stack" is a stack in which activities within an Android task are arranged. Android task is a collection of activities that users interact with when performing a certain job. Through this process activities are placed on the stack, in the order in which each activity is opened. Activities can be accessed later in reverse order by pressing the "back" button.

658 questions
374
votes
14 answers

Clear the entire history stack and start a new activity on Android

Is it possible to start an activity on the stack, clearing the entire history before it? The situation I have an activity stack that either goes A->B->C or B->C (screen A selects the users token, but many users only have a single token). In screen…
Casebash
  • 114,675
  • 90
  • 247
  • 350
262
votes
15 answers

Programmatically go back to the previous fragment in the backstack

Say I have an activity that has fragments added programmatically: private void animateToFragment(Fragment newFragment, String tag) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.fragment_container,…
Aske B.
  • 6,419
  • 8
  • 35
  • 62
232
votes
14 answers

How to prevent going back to the previous activity?

When the BACK button is pressed on the phone, I want to prevent a specific activity from returning to its previous one. Specifically, I have login and sign up screens, both start a new activity called HomeScreen when successful login/signup occurs.…
ecem
  • 3,574
  • 3
  • 27
  • 40
229
votes
20 answers

Fragment onResume() & onPause() is not called on backstack

I have multiple fragment inside an activity. On a button click I am starting a new fragment, adding it to backstack. I naturally expected the onPause() method of current Fragment and onResume() of new Fragment to be called. Well it is not…
Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
173
votes
16 answers

How can I maintain fragment state when added to the back stack?

I've written up a dummy activity that switches between two fragments. When you go from FragmentA to FragmentB, FragmentA gets added to the back stack. However, when I return to FragmentA (by pressing back), a totally new FragmentA is created and…
Eric
  • 5,323
  • 6
  • 30
  • 35
166
votes
6 answers

How to resume existing Fragment from BackStack

I am learning how to use fragments. I have three instances of Fragment that are initialized at the top of the class. I am adding the fragment to an activity like this: Declaring and initializing: Fragment A = new AFragment(); Fragment B = new…
Kaidul
  • 15,409
  • 15
  • 81
  • 150
157
votes
18 answers

Android: Remove all the previous activities from the back stack

When i am clicking on Logout button in my Profile Activity i want to take user to Login page, where he needs to use new credentials. Hence i used this code: Intent intent = new Intent(ProfileActivity.this, …
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
130
votes
11 answers

How to prevent multiple instances of an Activity when it is launched with different Intents

I've come across a bug in my application when it is launched using the "Open" button on the Google Play Store app (previously called Android Market). It seems that launching it from the Play Store uses a different Intent than launching it from the…
bsberkeley
  • 1,301
  • 2
  • 9
  • 3
125
votes
9 answers

Problems with Android Fragment back stack

I've got a massive problem with the way the android fragment backstack seems to work and would be most grateful for any help that is offered. Imagine you have 3 Fragments [1] [2] [3] I want the user to be able to navigate [1] > [2] > [3] but on the…
Chris Birch
  • 2,041
  • 2
  • 19
  • 22
119
votes
6 answers

How to Reverse Fragment Animations on BackStack?

I thought the system would reverse animations on the backstack when the back button is pressed when using fragments using the following code: FragmentManager fm = getFragmentManager(); FragmentTransaction ft =…
user742030
117
votes
17 answers

get the latest fragment in backstack

How can I get the latest fragment instance added in backstack (if I do not know the fragment tag & id)? FragmentManager fragManager = activity.getSupportFragmentManager(); FragmentTransaction fragTransacion = fragMgr.beginTransaction(); /****After…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
105
votes
12 answers

Fragments onResume from back stack

I'm using the compatibility package to use Fragments with Android 2.2. When using fragments, and adding transitions between them to the backstack, I'd like to achieve the same behavior of onResume of an activity, i.e., whenever a fragment is…
100
votes
11 answers

Android: open activity without save into the stack

I have 2 activities: Main and List. From Main you can open List; from List you can open Main. I'd like it so that every opening of List does not get saved into the 'history'. So, pressing back from Main cannot return to List. Is it possible?
realtebo
  • 23,922
  • 37
  • 112
  • 189
89
votes
5 answers

How to pop fragment off backstack

I have an activity A, which calls fragment Bf, which calls fragment Cf. I want Bf to be placed in the backstack when Cf is called so that users can navigate back to it. However, if a specific button is pressed in Cf, I would like Bf to be removed…
user2085335
  • 1,059
  • 1
  • 8
  • 11
58
votes
5 answers

Navigating back to FragmentPagerAdapter -> fragments are empty

I have a Fragment (I'll call it pagerFragment) that is added to the backstack and is visible. It holds a viewPager with a FragmentPagerAdapter. The FragmentPagerAdapter holds (let's say) two fragments: A and B. First adding of the fragments works…
1
2 3
43 44