Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6793823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:08:49+00:00 2026-05-26T18:08:49+00:00

Possible Duplicate: Separate Back Stack for each tab in Android using Fragments I’ve recently

  • 0

Possible Duplicate:
Separate Back Stack for each tab in Android using Fragments

I’ve recently started working on an application with fragments inside a tab host within a FragmentActivity.. the Android documentation said to do this as the TabActivity class is now deprecated. In order to use fragments, I am using the android v4 support library.

Currently my app consists of one tab within which the fragments exist. To navigate to new fragments within the tab I have been using the following code (which seems to be correct based on the documentation):

FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(containerId, newFragment);
ft.addToBackStack(null);
ft.commit();

All was well and good until I hit the back key to navigate to a previous fragment and realised that all of my view state had pretty much been destroyed.. what was happening is that the onCreateView() method was being called again on my previous fragment even though its views had previously been created… why is this? I’ve searched around on how to properly maintain state with fragments but I can’t seem to find decent documentation on this.

What I then tried was to use the

ft.add(containerId, newFragment);

instead of

ft.replace(containerId, newFragment);

This in fact worked quite well in that my view state was retained – onCreateView() was not called each time my previous fragments were shown. However, what I then began to notice was that I could interact with components (button, etc.) from previous fragments lying below the current fragment, even though I couldn’t see the components!? I read somewhere that the following method should be used to save some state:

public void onSaveInstanceState (Bundle outState)

I implemented this method, however, it was never called! I also noticed that the bundles past to the onCreateView() and onActivityCreated() methods are always null. Surely Google has not made it this difficult to achieve something like this and I must be missing something? Any help on how to correctly maintain a fragment’s view state will be greatly appreciated!

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:08:50+00:00Added an answer on May 26, 2026 at 6:08 pm

    Have a look at this question – I think the two may be related and you might be able to work around this issue.

    Separate Back Stack for each tab in Android using Fragments

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Date validation in PHP? date validation for year, month, day each separate.
Possible Duplicate: Schema for a multilanguage database I'm working on a web application that
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: How do I Create a Comma-Separated List using a SQL Query? I
Possible Duplicate: MySQL query using an array How to use an array of values
Possible Duplicate: Way to have compiled python files in a separate folder? When python
Possible Duplicate: Android Spinner OnItemSelected Called Erroneously (without user action on opening spinner) Does
Possible Duplicate: How does @synchronized lock/unlock in Objective-C? I have an application that creates
Possible Duplicate: separate the ids and store in two different array String response=@ hr
Possible Duplicate: Loading DLLs into a separate AppDomain What is the proper way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.