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 8040027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:45:34+00:00 2026-06-05T03:45:34+00:00

I’m creating a tablet optimised application using fragments. I have a thin navigation fragment

  • 0

I’m creating a tablet optimised application using fragments. I have a thin navigation fragment down the left hand side with buttons to controls what fragments will be loaded into the two ViewGroup containers which take up the rest of the screen.

For example, if a button in the navigation fragment is pressed, the 1st container will be loaded with an item list fragment (eg for settings, customers etc) and the second container will be loaded with fragment to show the item details.

Since I want to retain the fragments in memory (so, when navigating from Settings to Customers and then back to Settings, the previous Settings fragments should be there so the user doesn’t lose where they were up to) – I have created fragments instance variables for the Activity

SettingsListFragment settingsListFragment;
SettingsDetailFragment settingsDetailFragment;
CustomerListFragment customerListFragment;
CustomerDetailFragment customerDetailFragment;

I then create these fragments when neccessary and replace the containers with the fragments as needed. eg.

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if(settingsListFragment == null){
   settingsListFragment = new SettingsListFragment();
}           

fragmentTransaction.replace(R.id.fragment_container_left, settingsListFragment);
fragmentTransaction.commit();

My question is, how can I retain these instances accross an orientation change?

I’m assuming that I shouldn’t use the activities onRetainNonConfigurationInstance() method according to
http://developer.android.com/resources/articles/faster-screen-orientation-change.html because “Be very careful with the object you pass through onRetainNonConfigurationChange() …This means you should never pass a View, a Drawable, an Adapter, etc”

I’ve also attempted to get the Fragment from the fragment manager,
Fragment clf = fragmentManager.findFragmentByTag("CLIENT LIST");
but it comes back as null. I think it gets released after the fragment is replaced.

Thanks for any help/advice.

  • 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-06-05T03:45:36+00:00Added an answer on June 5, 2026 at 3:45 am

    You can’t (or really shouldn’t) retain fragments in that way. I’m guessing it’s state you want to keep.

    If you store your state in onSaveInstanceState() you can later retrive it in onCreate() or onActivityCreate(). So after you go back (you’ll have to add the FragmentTransaction to the back stack) you can restore the state from the Bundle to which you saved it!

    FragmentManager will take care of handling configuration changes and restoring your fragments in their current views.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
Thanks in advance for your help. I have a need within an application to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.