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
55
votes
2 answers

How to get a list of backstack fragment entries in android?

I'm working on an application in which tabs are implemented using FragmentActivity. Since, tabs are required throughout the application, fragments are used extensively to make the application compatible on all the versions of android. As a…
Harshal Kshatriya
  • 5,630
  • 11
  • 44
  • 60
54
votes
10 answers

How to clear the Android Stack of activities?

I have an application with several Activities in Android and I want the user to be able to log-out by pressing a menu button. The problem I have is that A) Android doesn't let you terminate the application and B) even when I send the user to the…
Totic
  • 1,281
  • 1
  • 10
  • 21
51
votes
8 answers

Android - save/restore fragment state

I have an Activity in which I go through several fragments. In every fragment I have several views (EditText, ListView, Map, etc). How can I save the instance of the fragment that is shown at that moment? I need it to work when the activity is…
Stanete
  • 691
  • 1
  • 7
  • 13
39
votes
3 answers

Android: Fragments backStack

Im trying to load an new fragment when a method is called. This method creates a new fragment and "replaces" the other fragment: private void showTestFragment(Fragment oldFragment, boolean addBackStack, BaseAdapter adapter, int position) { …
Oritm
  • 2,113
  • 2
  • 25
  • 40
39
votes
4 answers

savedInstanceState when restoring fragment from back stack

Can I use savedInstanceState() to save the state when removing a fragment, then restore the state when I pop the fragment off the back stack? When I restore the fragment from the back stack, savedInstanceState bundle is always null. Right now, the…
heero
  • 1,941
  • 5
  • 23
  • 33
37
votes
3 answers

How to replace fragment C with fragment A when back button is pressed?

My scenario : Activity 1 consists of Fragments A-> B-> C. All the fragments are added using this code : FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); …
35
votes
3 answers

Fragment methods: attach(), detach(), remove(), replace(), popBackStack()

I am very confused between these functions and their purposes. What I have observed that using replace() replaces the existing fragment with a new one. We can use addToBackStack(null) to put that fragment in back stack so we can go back to the…
Vikram Gupta
  • 6,496
  • 5
  • 34
  • 47
34
votes
3 answers

Resume the Activity instead of Starting if already exists in back stack

I have an Activity_1 after a lot of steps, say Activity_2 > Activity_3 .... in some Activity_n I change some data related to Activity_1 and call it using Intent intent = new Intent(Activity_n.this,…
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
31
votes
8 answers

Fragment's onResume() not called when popped from backstack

Hi I am developing android application in which I am using I am using single Activity and 3 fragments. So consider I have 3 fragments A B C. When I switch from A to B, I am adding Fragment to backstack and simillar for B to C. Now when I click back…
nilkash
  • 7,408
  • 32
  • 99
  • 176
27
votes
6 answers

Fragment addToBackStack() and popBackStackImmediate() not working

I am currently building an application for Android (14 <= SDK <= 21) by using one ActionBarActivity and more Fragments, such as ListFragment and MapFragment, which are swapped within a single FrameLayout view. The ActionBarActivity automatically…
Emanuele
  • 674
  • 1
  • 8
  • 19
25
votes
7 answers

Misbehaviour of Backstack of activity when activity destroyed

I have two activities; let's say A and B. In activity A there is a broadcast receiver registered that listens for a particular event which will finish activity A. I am registering the broadcast receiver in onCreate(), and destroying it in…
24
votes
11 answers

Backstack management : Restarter must be created only during owner's initialization stage

I am using a bottom navigation bar in my MainActivity to handle some fragments. This is the code used for switching between them: private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> if…
Gabi
  • 667
  • 1
  • 7
  • 17
24
votes
4 answers

noHistory vs finish() - Which is preferred?

I don't want my application to show few Activity (say SplashScreenActivity) when pressing back button. So I've used noHistory=true in my Manifest.xml for that Activity as show below:
Gokul Nath KP
  • 15,485
  • 24
  • 88
  • 126
21
votes
8 answers

How to find back stack activities in an android application?

I have an application with activities back stack A -> B -> C -> D -> E. Now at activity E, I want to know the back stack activities that I navigated from. How do I find this??
azzits
  • 345
  • 2
  • 3
  • 10
21
votes
2 answers

Android Reorder Fragment Backstack

I have a number of pages/fragments listed in my navigation drawer, the user is likely to switch between these frequently and I want them in the backstack so that they can navigate back, but I only want one instance of each fragment in the backstack…
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
1
2
3
43 44