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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:22:25+00:00 2026-06-10T11:22:25+00:00

I am stuck with trying to figure out what is causing my app to

  • 0

I am stuck with trying to figure out what is causing my app to lose data in two ListViews, one in each of two tabs, both of which are ListFragments. The ListViews are empty randomly on a phone when you bring the app to the forefront.

I’m guessing I’m missing something with how data is to be restored when bringing back up the application. Generally the app restores and data in both tabs are there.

However, only on a real phone it seems, the data will be gone from the ListViews but I cannot find a reproducible pattern.

I’ve used DDMS to simulate a garbage collection in many combinations and I can’t reproduce the loss of data. Here is how I’m dealing with the life cycle, simplified and basically total pseudo code.

I’ve looked over the lifecycle structure and thought I had it working.

Am I refreshing incorrectly?

Main activity

public class MyActivity extends FragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // I don't refresh here
        // add both tabs to the tab adapter
    }

    public void onRestart() {
        super.onRestart(); 
        reloadTab1();
        reloadTab2();
    }
}

Tab 1

public class MyTab1 extends ListFragment {
    static MyTab1Adapter mAdapter;
    ArrayList<MyObject> mItems;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // retain state
        setRetainInstance(true);
        reloadTab1(getActivity());
    }

    public void reloadTab1(Context context) {
        mItems = updateItems();

        if (mAdapter == null) {
            mAdapter = new MyTab1Adapter(context, R.layout.tab1, mItems);
            setListAdapter(mAdapter);
        }           
        else {
            mAdapter.setNewList(mItems);
            mAdapter.notifyDataSetChanged();
        }
    }
}

Tab 2

public class MyTab2 extends ListFragment {
    static MyTab2Adapter mAdapter;
    ArrayList<MyObject> mItems;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // retain state
        setRetainInstance(true);
        reloadTab2(getActivity());
    }

    public void reloadTab2(Context context) {
        mItems = updateItems();

        if (mAdapter == null) {
            mAdapter = new MyTab2Adapter(context, R.layout.tab2, mItems);
            setListAdapter(mAdapter);
        }           
        else {
            mAdapter.setNewList(mItems);
            mAdapter.notifyDataSetChanged();
        }
    }
}
  • 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-10T11:22:27+00:00Added an answer on June 10, 2026 at 11:22 am

    You had a small typo in your code, you used the onRestart callback but called the onResume mthod from the super class instead of super.onRestart();.

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

Sidebar

Related Questions

I'm stuck trying to figure this one out.. We currently have a date criteria
I've been stuck trying to figure out why a counter cache on my (parent)
I have progressed with my app but I am stuck with trying to figure
I am stuck trying to figure out how to initiate a WSDL connection with
I'm trying to automate file comment headers. I'm stuck trying to figure out how
I'm stuck trying to implement a data model for an app to be deployed
Im stuck trying to figure out how to pull the information from my pre-populated
I'm stuck again trying to figure out how to out the button clicked to
So I'm stuck trying to figure out how Google Analytics avoids spoofing. Sure, when
I am stuck trying to figure out how to alter my collision detection 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.