Getting the error “Java.lang.IllegalStateException Activity has been destroyed” when using tabs with ViewPager

前端 未结 13 2183
再見小時候
再見小時候 2020-11-22 11:53

I have an application that consists of using ActionBarSherlock in tab mode.I have 5 tabs and the content of each tab is handled using fragments. For tab2 though, I have a fr

13条回答
  •  长情又很酷
    2020-11-22 12:22

    I encountered the same issue when calling super.onCreate() at the end of my method. The reason: attachActivity() is called in onCreate() of FragmentActivity. When overriding onCreate() and, for example, creating tabs, the Tab manager will try to switch to a fragment while not having the activity attached to the FragmentManager.

    Simple solution: Move the call to super.onCreate() to the head of the function body.

    In general, it seems there are loads of reasons this issue may occur. This is just another one ...

    Matthias

提交回复
热议问题