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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:12:31+00:00 2026-06-17T20:12:31+00:00

I have an application where whenever I exit the application via the home hardware

  • 0

I have an application where whenever I exit the application via the home hardware button, it should return to the last state the application is in. However, when I launch the application again, the application shows a white screen with only my header bar. And when I click on the header bar’s button, the application crashes with the IllegalStateException where the application cannot find the method for the button clicked.

I am currently implementing with Sherlocks Fragment, where the header bar is an action bar. I’m also using HTC Rhyme, Version 2.3 (Gingerbread). The following is the codes for the addition of fragments into my main app.

Codes to add the fragments within the onCreate method in the activity:

FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
Bundle bMain = getIntent().getExtras();
String statusCheck = "";
if (bMain != null) {
    statusCheck = bMain.getString("statusCheck");
}
if (statusCheck.equals("web")) {
    MyWebViewFragment webfrag = new MyWebViewFragment();
    trans.add(R.id.container,webfrag, "WebViewFragment");
} else if(statusCheck.equals("traveloguelist")) {
    MyTravelogueListFragment travelfrag = new MyTravelogueListFragment();
    trans.add(R.id.container,travelfrag, "TravelogueListFragment");
}
trans.commit();

This is the codes when I change a fragment:

MyTravelogueListFragment travelfrag = new MyTravelogueListFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.container, travelfrag).addToBackStack(null).commit();

[Edit]

I realized after much reading and running that the main issuei have is that upon resuming the application, the activity is actually created again. Thus, some of the parameters i passed in does not get registered, resulting in the wrong display. I THINK this is the error that is causing that to happen:

Previously focused view reported id "myresID" during save, but can't be found during restore.

However, I don’t know how you force the application to remember the previous state of the fragment? Or is there any other way around this problem?

I’m still very stuck with this problem. Will really appreciate it if someone can help me!

  • 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-17T20:12:32+00:00Added an answer on June 17, 2026 at 8:12 pm

    After much trial and error and many readings, I finally found a way to sort of solve my problem.

    From what I understand, this problem will occur due to the Activity’s life cycle. The comment by Tseng in this forum was quite comprehensive:
    http://forum.unity3d.com/threads/127794-Android-Apps-crashing-on-resume

    It seems that during the time when other applications are invoked when a certain activity is onPause/onStop, Android might free up some of its memory the activity is currently holding on to if there is insufficient memory required. In this case, all the current objects or variable the paused activity is having will be destroyed. Thus, when the activity is back on focus, the onCreate is actually invoked again. Thus, the activity will have no idea which fragment I am currently require.

    However, I realized that it will always call the saveInstanceState which is essentially a bundle object. So I did the following:

    onSaveInstanceState method

      @Override
      public void onSaveInstanceState(Bundle bundle) {
          //activityFrag is a string object that tells me which fragment i am in currently
          bundle.putString("statusCheck", activityFrag);
      }
    

    onCreate method

    if (savedInstanceState != null) {
        getSupportFragmentManager().popBackStack(null, getSupportFragmentManager().POP_BACK_STACK_INCLUSIVE);
        //return;
        statusCheck = savedInstanceState.getString("statusCheck");
    } else {
        statusCheck = b.getString("statusCheck");
    }
    

    What I have done is to remove all the fragments I have stacked thus far to remove any issues where there is missing information needed. So this is like starting anew again. The status check just determine which fragment the user has last visited.

    After much testing, it seems like it does solve my problem. though I wouldn’t say it is perfect. One of the main downfall I have is that whenever I change my fragment, I have to update and change my statusCheck to make sure the correct fragment will be called. However, I have to admit this way is a little unorthodox and might not be very correct.

    If any of you have any better ideas, please feel free to share!

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

Sidebar

Related Questions

We have an application using the IBM Informix driver. Whenever we try to open
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I have a PHP application using an Oracle XE database. Whenever I add a
I have a Web application ( http://www.holidaystreets.com ), it has around 120,000+ pages. Whenever
i have used impersonation in this application. whenever this error occurs i required to
I have two Activities along with one Application class, and whenever I call my
I have set the WA_DeleteOnClose widget attribute in a MainWindow. setAttribute(Qt::WA_DeleteOnClose); However, whenever I
I have an application that uses a tab bar and whenever it launches it
I have a published application in C#. Whenever I close the main form by
i have a tabforms in my application and whenever i open the multiple forms

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.