android:为什么FragmentActivity.onDestroy调用片段onCreateView

时间:2015-11-10 13:11:18

标签: android android-fragments

崩溃发生在

之下
    at com.activity.upgrade.VersionFragment.parse(VersionFragment.java:73)
at com.activity.upgrade.VersionFragment.onCreateView(VersionFragment.java:57)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1120)
at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop(FragmentManager.java:1956)
at android.support.v4.app.FragmentActivity.onReallyStop(FragmentActivity.java:790)
at android.support.v4.app.FragmentActivity.doReallyStop(FragmentActivity.java:767)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:314)
at com.common.BaseActivity.onDestroy(BaseActivity.java:107)
at android.app.Activity.performDestroy(Activity.java:5421)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3494)

很奇怪片段onCreatView不是从Activity onCreate调用,而是从onDestroy调用。在系统或某些第三方工具终止应用程序后进入应用程序时会发生这种情况。有人见过这个吗?

********** UPDATE **********

从源代码来看,似乎与Fragment状态有关。当FragmentActivity在其onDestroy时,它的状态是Fragment.INITIALIZING或Fragment.CREATED状态。我认为应该处于错误的状态。

1 个答案:

答案 0 :(得分:0)

请参阅here

stacktrace没问题,问题可能出在onDestroy或onResume回调上。您应该在onResume方法中使用super.onResume或super.OnDestroy!

谷歌应用程序演示也必须首先调用子类的方法。enter image description here