I do a lot of search about this problem but no answer helps me.
I saw a same question in here but it can not help, so I post my question with the hope that any guy can help me. It's serious to me.
I have an Activity
(called activity
A, it's MainActivity) with TabLayout
and ViewPager
, which contains 5 Fragments
.
In normal case, everything is ok. But some time if I try to re-open A1
with below scenario
- Start
Activity
A - From one of 5
fragments
above, I start a new Activity called B. - From B, I tried to start
Activity
C - From C, start
Activity
A above and clear all of theactivities
in backstack byintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
I got below Error
:
java.lang.IllegalStateException: No host at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1239) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1234) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2046) at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1989) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1092) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
Since now, I can not launch my app any more, each time I try to launch my application, I got the exception with the same Error in above.
I tried to use the solution in this topic but still can not resolve my issue
I do investigate and found that Exception occurs in FragmentManager class by code :
if (mHost == null && newState != Fragment.INITIALIZING) {
throw new IllegalStateException("No host");
}
I have no idea why mHost
is null and every time I try to call commit
from fragmentManager
, the exception
will be thrown.
If I clear data
of application
, it will back to normal.