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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:56:15+00:00 2026-06-15T06:56:15+00:00

I’m building an Android app right now, and if I press the Home button

  • 0

I’m building an Android app right now, and if I press the Home button or lock the screen after a given scenario (it’s really specific), my app crashes with the error:

10-26 13:57:50.132: E/AndroidRuntime(8663): FATAL EXCEPTION: main
10-26 13:57:50.132: E/AndroidRuntime(8663): java.lang.RuntimeException: Unable to pause activity {.views.MainActivity}: java.lang.IllegalStateException: Failure saving state: active LoginFragment{4053d5a0} has cleared index: -1
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2365)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2322)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2302)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.ActivityThread.access$1700(ActivityThread.java:117)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:949)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.os.Looper.loop(Looper.java:130)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.ActivityThread.main(ActivityThread.java:3694)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at java.lang.reflect.Method.invokeNative(Native Method)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at java.lang.reflect.Method.invoke(Method.java:507)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at dalvik.system.NativeStart.main(Native Method)
10-26 13:57:50.132: E/AndroidRuntime(8663): Caused by: java.lang.IllegalStateException: Failure saving state: active LoginFragment{4053d5a0} has  cleared index: -1
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1695)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:499)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at views.MainActivity.onSaveInstanceState(MainActivity.java:62)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.Activity.performSaveInstanceState(Activity.java:1042)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1181)
10-26 13:57:50.132: E/AndroidRuntime(8663):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2347)
10-26 13:57:50.132: E/AndroidRuntime(8663):     ... 12 more

I have no idea what this error comes from and what the general cause of this error is.

Edit:
I’m sorry, I’ll give out some more information. Basically, I have a FragmentActivity (which is my Tabhost) and each tab is a fragment from which I can navigate to another fragment.

The specific scenario is as following:

  • Application opens, Tab 0 with Fragment 0 (LoginFragment) is displayed.
  • User logs in, LoginFragment gets replaced with ProfileFragment.
  • From the ProfileFragment, the user has the ability to logout, and does so, which replaces the Profilefragment with Loginfragment again.
  • User navigates to different Tab from TabHost.
  • User navigates back to the original Tab.
  • User then locks screen / uses the Home button, crashing the application with the given error.

I only get the error on this specific scenario.

The error originates from the TabManager class within the TabHost FragmentActivity, here is the code (mainly from the Android FragmentTabs example, with a few minor adjustments):

public static class TabManager implements TabHost.OnTabChangeListener {
    private final FragmentActivity mActivity;
    private final TabHost mTabHost;
    private final int mContainerId;
    private final HashMap<String, TabInfo> mTabs = new HashMap<String, TabInfo>();
    TabInfo mLastTab;

    static final class TabInfo {
        private final String tag;
        private final Class<?> clss;
        private final Bundle args;
        private Fragment fragment;

        TabInfo(String _tag, Class<?> _class, Bundle _args) {
            tag = _tag;
            clss = _class;
            args = _args;
        }
    }

    static class DummyTabFactory implements TabHost.TabContentFactory {
        private final Context mContext;

        public DummyTabFactory(Context context) {
            mContext = context;
        }

        public View createTabContent(String tag) {
            View v = new View(mContext);
            v.setMinimumWidth(0);
            v.setMinimumHeight(0);
            return v;
        }
    }

    public TabManager(FragmentActivity activity, TabHost tabHost, int containerId) {
        mActivity = activity;
        mTabHost = tabHost;
        mContainerId = containerId;
        mTabHost.setOnTabChangedListener(this);
    }

    public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
        tabSpec.setContent(new DummyTabFactory(mActivity));
        String tag = tabSpec.getTag();

        TabInfo info = new TabInfo(tag, clss, args);

        // Check to see if we already have a fragment for this tab, probably
        // from a previously saved state.  If so, deactivate it, because our
        // initial state is that a tab isn't shown.
        info.fragment = mActivity.getSupportFragmentManager().findFragmentByTag(tag);
                if (info.fragment != null && !info.fragment.isDetached()) {
                    FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
                    ft.detach(info.fragment);
                    ft.commit();
                }

                mTabs.put(tag, info);
                mTabHost.addTab(tabSpec);
    }

    public void onTabChanged(String tabId) {

        TabInfo newTab = mTabs.get(tabId);
        if (mLastTab != newTab) {
            FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
            if (mLastTab != null) {
                if (mLastTab.fragment != null) {
                    ft.detach(mLastTab.fragment);
                }
            }
            if (newTab != null) {
                if (newTab.fragment == null) {
                    newTab.fragment = Fragment.instantiate(mActivity,
                            newTab.clss.getName(), newTab.args);
                    ft.add(mContainerId, newTab.fragment, newTab.tag);

                } else {
                    ft.attach(newTab.fragment);
                }
            }
            int backEntryCount = mActivity.getSupportFragmentManager().getBackStackEntryCount();
            if (backEntryCount > 1) {
                mActivity.getSupportFragmentManager().popBackStack(null, 0);
            }

            //If there's a current BackTrace, remove it and instantiate the original fragment of the selected tab.
            FragmentManager fm = mActivity.getSupportFragmentManager();
            if (fm.getBackStackEntryCount() >= 1) {
                fm.popBackStack();
                newTab.fragment.getFragmentManager().beginTransaction().add(mLastTab.fragment.getId(), newTab.fragment = Fragment.instantiate(mActivity,
                        newTab.clss.getName(), newTab.args));
            }
            if (mActivity.getSupportFragmentManager().findFragmentByTag("userprofile") != null) {
                Fragment fragment = mActivity.getSupportFragmentManager().findFragmentByTag("userprofile");
                ft.detach(fragment);

            }
            if (newTab.fragment.getClass().getName().contains("Login") && Preferences.getUser(mActivity).getApikey() != null) {
                ft.replace(mLastTab.fragment.getId(), new ProfileFragment(), "userprofile");
                ft.detach(newTab.fragment);
            }

            if (mActivity.getSupportFragmentManager().findFragmentByTag("Profile") != null) {
                if (mActivity.getSupportFragmentManager().findFragmentByTag("Profile").isDetached() == true) {
                    System.out.println(true);
                    Fragment fragment = mActivity.getSupportFragmentManager().findFragmentByTag("Profile");
                    mActivity.getSupportFragmentManager().beginTransaction().replace(fragment.getId(), new LoginFragment(), "Profile").commit();
                }
            }
            mLastTab = newTab;
            ft.commit();  
            mActivity.getSupportFragmentManager().executePendingTransactions();

        }
    }
}
  • 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-15T06:56:18+00:00Added an answer on June 15, 2026 at 6:56 am

    Sorry for being late with this answer, but I found out why I had this error. For some reason I had multiple instances of my LoginFragment which was causing the crash. I removed some code so the fragment would be instanced only one time and I had no more crashes after that.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.