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

前端 未结 13 2317
再見小時候
再見小時候 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:20

    I had this problem and I couldn't find the solution here, so I want to share my solution in case someone else has this problem again.

    I had this code:

    public void finishAction() {
      onDestroy();
      finish();
    }
    

    and solved the problem by deleting the line "onDestroy();"

    public void finishAction() {
      finish();
    }
    

    The reason I wrote the initial code: I know that when you execute "finish()" the activity calls "onDestroy()", but I'm using threads and I wanted to ensure that all the threads are destroyed before starting the next activity, and it looks like "finish()" is not always immediate. I need to process/reduce a lot of “Bitmap” and display big “bitmaps” and I’m working on improving the use of the memory in my app

    Now I will kill the threads using a different method and I’ll execute this method from "onDestroy();" and when I think I need to kill all the threads.

    public void finishAction() {
      onDestroyThreads();
      finish();
    }
    

提交回复
热议问题