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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:12:47+00:00 2026-06-03T06:12:47+00:00

saveInstanceState() doesn’t work as expected. I’m trying to read the data so I don’t

  • 0

saveInstanceState() doesn’t work as expected.
I’m trying to read the data so I don’t have to do the query again when a user reselects the tab. The fragment is a tab in a actionbar. Everything works properly, I just can’t get savedInstanceState to be anything else then NULL, anyone has any idea?

This is my code:

public class SpecsFragment extends Fragment {
    private String mText;
    private ArrayList<HashMap> result;
    private Converter c;
    private View fragView;

public SpecsFragment() {
    mText = "specs";
    c = new Converter();
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    fragView = inflater.inflate(R.layout.product_info_fragment, container, false);

    return fragView;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);

    if(savedInstanceState == null) {

        Bundle args = getArguments();
        int id = Integer.parseInt(args.getString("id"));

        String query = "SELECT * FROM products WHERE id = " + id;

        try {
            ZoekQueryTask zoekQueryTask = new ZoekQueryTask(query);
            result = zoekQueryTask.getResults();
        }

        catch (Exception e) {
            Log.e("Afgevangen error", e.getMessage());
        }
    }
    else {
        result = new ArrayList();
        result.add((c.BundleToHashMap(savedInstanceState)));
    }

    TextView text = (TextView) fragView.findViewById(R.id.textView1);
    text.setText(mText);
    text.append("\n\n");
    text.append(result.get(0).get("ean").toString());
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState = c.HashmapToBundle(result.get(0));
}

}

Using

savedInstance.putAll(c.HashmapToBundle(result.get(0)));

Still does not work.

savedInstance.putBundle("results", c.HashmapToBundle(result.get(0)));

Doesn’t work either, anyone have any idea?

I solved the problem by working around it, instead of trying to store savedInstanceState. I wrote functions to get and set a Bundle from the fragments parent activity, and then get the activity by using:

YourActivity parent = (YourActivity) this.getactivity();

And just call the function for getting and setting a bundle which you write yourself.

  • 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-03T06:12:48+00:00Added an answer on June 3, 2026 at 6:12 am

    I solved the problem by working around it, instead of trying to store savedInstanceState. I wrote functions to get and set a Bundle from the fragments parent activity, and then get the activity by using:

    YourActivity parent = (YourActivity) this.getactivity(); 
    

    And just call the function for getting and setting a bundle which you write yourself

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

Sidebar

Related Questions

I'm trying to create an if statement, for example if the user doesn't type
I have a problem with SQLite, it doesn't work when i call DataBaseHelper(who store
i have problem with listview... i'm trying to add OnClickListener but in still doesn't
I have a problem with back button. He doesn't work. When I go from
Why isn't my Scrollview automatic scrolling? I don't get it.. it just doesn't move...
Why doesn't this work? Can Anyone tell me whats wrong with this onitemclicklistener? It
I am trying to work with Accelerometer Sensor. So i tried this example: http://blog.androgames.net/85/android-accelerometer-tutorial/
I wrote this code to try threads on Android, but it doesn't work. @Override
I have the following code that works but doesn't use my layout webscreen. @Override
I have this code for my app, it doesn't show any errors but everytime

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.