"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.
Questions tagged [back-stack]
658 questions
21
votes
3 answers
WebView reloading when Fragment in ViewPager is retained form BackStack
Here is a code for a basic Fragment which contains a WebView.
WebFragment.java
public class WebFragment extends Fragment {
String TAG = "WebFragment";
private WebView webView;
private String currentUrl = "http://www.google.com";
@Override
public…

Vishal Vijay
- 2,518
- 2
- 23
- 45
20
votes
3 answers
Fragment PopBackStack
I am getting a strange problem, while using Fragments and popping back them out.
I have one Fragment Activity:
Step1: I am attaching one Fragment in the onCreate of that Activity in the Starting named Fragment A as:
This is the onCreate of Fragment…

Gaurav Arora
- 8,282
- 21
- 88
- 143
19
votes
5 answers
Android : Return to previous fragment on back press
I have implemented Navigation Drawer which is a subclass of Activity. I have many fragments in my application. My question goes here
Imagine there are 3 fragments :
Fragment_1 : Fragment_2 : Fragment_3
When I start my application, Fragment_1 is…

Harsh
- 644
- 3
- 14
- 27
19
votes
3 answers
Android deep linking - Back stack
I am trying to implement deep linking in my Android application. I have been following this guide. I have an Android Activity that is started from and intent-filter in the Android manifest:

Jon G
- 1,656
- 3
- 16
- 42
19
votes
2 answers
Back button closing app even when using FragmentTransaction.addToBackStack()
None of the other questions I have read on stackoverflow have been able to help with my problem. As far as I can tell, I am doing everything correctly.
I have a master/detail flow with fragments.
Upon creation of the main activity, the master…

scottysseus
- 1,922
- 3
- 25
- 50
17
votes
10 answers
PopBackStack but keep the first fragment in android
I am working on fragment transaction, and the backstack is like this:
fragA => fragB => fragC => fragD
I would like to return to fragA after back fromn the fragD
fragD => onBackPress => fragA
So, I tried code…

user782104
- 13,233
- 55
- 172
- 312
16
votes
5 answers
How to find whether activity is last activity in stack
I am opening a link in my app and once back is pressed I want to show HomePage to retain user for some more time. I have been trying to acheive this but unable to do so. I get homeLauncher activity as my top as well as baseActivity.
DeepLink Tap >…

user1288005
- 890
- 2
- 16
- 36
16
votes
3 answers
popBackStack causes calling oncreateView of fragment again and again
I have 3 fragment A, B,C.I wrote piece of code for replacing them and maintaining backstack:
public void addFragment(Fragment fragmentToAdd, String fragmentTag) {
FragmentManager supportFragmentManager = getSupportFragmentManager();
…

Anshul
- 9,312
- 11
- 57
- 74
15
votes
1 answer
Get the last fragment in back stack
I have seen this post but the solutions posted here are not working for me: get the latest fragment in backstack
When I replace a fragment for another I use:
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction ft =…

kiduxa
- 3,339
- 11
- 37
- 52
14
votes
2 answers
How to remove previous back stack entry from FragmentManager?
I have an activity in which I am switching fragments using following method:
public void setCurrentFragment(Fragment fragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
…

nemezis
- 536
- 1
- 6
- 21
14
votes
5 answers
print the current back stack in the log
Is there a way to print the current back stack of the current task in an Android app? In particular, I want to understand when an activity is popped off the stack after its onDestroy() is called.

dacongy
- 2,504
- 3
- 30
- 48
13
votes
3 answers
Stop fragment from being recreated after resume?
I am using several fragments to be dynamically added into activity. Everything works fine, when I press back-button, the fragments go to backstack. And when I resume it, it appears. But everytime on Resume, it is recreating the fragment and call…

Kaidul
- 15,409
- 15
- 81
- 150
12
votes
3 answers
Clearing the full Android activity stack on older SDKs (that lack FLAG_ACTIVITY_CLEAR_TASK)
I've done qui a bit of reading and searching on SO, but can't find a way to clear the current activity stack. The context of my app is an activity started by a a background service / notification.
Imagine that my app allows you to organise a list of…

Romain
- 2,318
- 1
- 23
- 31
12
votes
7 answers
Android Fragment Back Stack
I have used multiple Fragments in my Project. I want to save a Fragment's state and restore this state when I come back to this. In this Fragment I show multiple images which change on button click. I use the following code for this:
String…

tech_android
- 719
- 1
- 7
- 18
12
votes
1 answer
Recreate the backstack in Android
I have just implemented a way to change the theme in my app. Pressing a button sets a value in SharedPreferences, then the Activity is recreated, and the theme is changed due to the flag.
The problem is how to handle the backstack. Simply recreating…

Tim Rae
- 3,167
- 2
- 28
- 35