3

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

  1. Start Activity A
  2. From one of 5 fragments above, I start a new Activity called B.
  3. From B, I tried to start Activity C
  4. From C, start Activity A above and clear all of the activities in backstack by intent.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.

Community
  • 1
  • 1
ThaiPD
  • 3,503
  • 3
  • 30
  • 48
  • Can you post code for a simple example to help other people replicate? – Michiyo May 10 '16 at 17:45
  • It's a big project with many Activities and Fragments, and I in the log it did not point me which part causes the problem, So I don't know which one I could post in here :( – ThaiPD May 11 '16 at 03:11
  • But that makes it very difficult for anyone to provide help. Suppose you made a copy of your project and started stripping out irrelevant parts. Ideally, you'll either identify the problem yourself (when you remove something and the problem goes away) or wind up with a simple example of how to reproduce the problem. – Michiyo May 11 '16 at 16:00

0 Answers0