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
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();
}
I force the fragment containing the child fragment to NULL in onPause and it fixes my problem
fragment = null;
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
I got the very same error when trying to access the child FragmentManager
before the fragment was fully initialized (i.e. attached to the Activity or at least onCreateView()
called). Else the FragmentManager
gets initialized with a null
Activity causing the aforementioned exception.
I encountered the same issue and lateron found out that, I have missed call to super.onCreate( savedInstanceState );
in onCreate()
of FragmentActivity.
I had this error because I was using LocalBroadcastManager and I did:
unregisterReceiver(intentReloadFragmentReceiver);
instead of:
LocalBroadcastManager.getInstance(this).unregisterReceiver(intentReloadFragmentReceiver);