问题
I'm getting a weird error in one of my activities. I can't figure out why this is happening.
I have an Activity
which displays search results to the user. When he taps on one of them, a detailed page for that result is shown, and when he closes that Activity
it goes back to the search result screen. It works fine for the most part, except on certain devices where it crashes as soon as the Activity
resumes.
The stack trace is also useless as it is being thrown internally by the support fragment manager.
03-18 15:32:48.987: E/AndroidRuntime(26456): FATAL EXCEPTION: main
03-18 15:32:48.987: E/AndroidRuntime(26456): java.lang.IllegalStateException: No activity
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1871)
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:455)
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.support.v4.app.FragmentActivity$1.handleMessage(FragmentActivity.java:91)
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.os.Looper.loop(Looper.java:150)
03-18 15:32:48.987: E/AndroidRuntime(26456): at android.app.ActivityThread.main(ActivityThread.java:4333)
03-18 15:32:48.987: E/AndroidRuntime(26456): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 15:32:48.987: E/AndroidRuntime(26456): at java.lang.reflect.Method.invoke(Method.java:507)
03-18 15:32:48.987: E/AndroidRuntime(26456): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
03-18 15:32:48.987: E/AndroidRuntime(26456): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
03-18 15:32:48.987: E/AndroidRuntime(26456): at dalvik.system.NativeStart.main(Native Method)
03-18 15:32:48.987: W/ActivityManager(241): Force finishing activity com.my.app/.SearchActivity
My Activity
is extending FragmentActivity
, but only because I need to use the LoaderManager
. Moving to the standard library is out of the question since my app has to support Android 2.3.
I have tried updating to the newer version of the support library, and reverting to an older version, but no luck.
How can I fix this?
回答1:
Never mind, I got the answer - It's the same as THIS one.
Someone had overriden onWindowFocusChanged(boolean hasFocus)
in the details page but was calling super.onResume()
instead. I do wish that the error message had been more clear though.
回答2:
In my case it is due to activity automaticay restared so just set lounch mode single task
来源:https://stackoverflow.com/questions/15498216/getting-a-java-lang-illegalstateexception-no-activity-when-resuming-an-activity