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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:04:15+00:00 2026-06-10T22:04:15+00:00

I use ListFragment setRetainInstance (true); does not work, I do not know why savedInstanceState

  • 0

I use ListFragment

setRetainInstance (true); does not work, I do not know why

savedInstanceState == null

my sources

  public class Fragment_Left extends ListFragment {

        @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
            Log.d(LOG_TAG, "Fragment1 onAttach");
        }

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Log.d(LOG_TAG, "Fragment1 onCreate");
        }

        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);

            setRetainInstance(true);

        }

        @Override
        public void onListItemClick(ListView l, View v, int position, long id) {
            getListAdapter().getItem(position);

        }



         public void onSaveInstanceState(Bundle state) {
                super.onSaveInstanceState(state);
                Log.i(LOG_TAG, "onSaveInstanceState()");


            }


}

    public class Fragment_Left extends ListFragment {
        private ArrayList<Menu_item> menu_list;  .....

     @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);

            setRetainInstance(true);   
menu_list = new ArrayList<Menu_item>();......

but After I turned Screen menu_list is null, or I did something wrong?

  • 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-10T22:04:16+00:00Added an answer on June 10, 2026 at 10:04 pm

    how do I store an array in a fragment?

    I am assuming that by “store an array in a fragment” that you mean “retain an array used by a fragment across configuration changes”. If so:

    Option #1: Put it in a data member of the fragment, and call setRetainInstance(true) on that fragment.

    Option #2: If the array is of a data type that is supported by Bundle, override onSaveInstanceState(), put the data in the Bundle, and retrieve that data in other methods in the new fragment instance created after the configuration change (e.g., onCreateView()).

    Option #3: If the array really represents the data model of your app, hold it in a central persistent spot that the old and new fragment instances can access, such as a database or a file.

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

Sidebar

Related Questions

i have about 60 fragments ListFragment , now i use each Listfragment with another
I'm trying to create a custom ArrayAdapter to use for my ListFragment . Right
My app is using a ListFragment on left side that the user can use
I'm using the Android compatibility library, targeting Android 2.2. If I use ListFragment With
Use case: I find a piece of code that I do not understand at
use this code, in the Preferences activity, to know when the reset preference has
I have a simple question, I know you can use: setListAdapter(new ArrayAdapter<String> (getActivity(), R.layout.your_layout,
I know you can use this: android:configChanges=orientation to eliminate redraws on orientation changes. Although
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
Use case: A does something on his box and gots stuck. He asks B

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.