Java.lang.IllegalStateException:No activity

Source: Internet
Author: User

Error Tip:

Java.lang.IllegalStateException:No activity
At Android.support.v4.app.FragmentManagerImpl.moveToState (fragmentmanager.java:1075)
At Android.support.v4.app.FragmentManagerImpl.moveToState (fragmentmanager.java:1070)
At android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (fragmentmanager.java:1861)
At android.support.v4.app.Fragment.performActivityCreated (fragment.java:1474)
At Android.support.v4.app.FragmentManagerImpl.moveToState (fragmentmanager.java:931)
At Android.support.v4.app.FragmentManagerImpl.moveToState (fragmentmanager.java:1088)

.......

This problem arises after addressing the issues identified in the previous article (http://blog.csdn.net/leewenjin/article/details/19409863). The problem-solving method is a reference article:

Http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed

The principle problem and solution of the bug appears
This seems is a bug in the newly added support for nested fragments. Basically, the child fragmentmanager ends up with a broken internal the ' it is detached ' the activity. A short-term workaround that fixed it's for me are to add the following to Ondetach () of every Fragment which your call Getchi Ldfragmentmanager () on:

Workaround Rewrite Ondetach ()

@Override public
    void Ondetach () {
    	super.ondetach ();
    	try {
    	    Field Childfragmentmanager = Fragment.class.getDeclaredField ("Mchildfragmentmanager");
    	    Childfragmentmanager.setaccessible (true);
    	    Childfragmentmanager.set (this, null);

    	catch (Nosuchfieldexception e) {
    	    throw new RuntimeException (e);
    	} catch (Illegalaccessexception e) {
    	    throw New RuntimeException (e);
    	}
    
    }

One of the Field is

Java.lang.reflect.Field

Causes of Bugs
If you look in the implementation of Fragment, you'll be there when moving to the detached state, it ' ll be reset its internal State. However, it doesn ' t reset Mchildfragmentmanager (this was a bug in the current version of the support library). This causes the reattach the "Child fragment manager" when the fragment are reattached, causing the exception you saw.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.