Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException: Fragment not attached to Activity #51

Open
lingling-fan opened this issue Sep 6, 2017 · 1 comment
Open

IllegalStateException: Fragment not attached to Activity #51

lingling-fan opened this issue Sep 6, 2017 · 1 comment

Comments

@lingling-fan
Copy link

//package name: com.casimirlab.simpleDeadlines
//version: 3.2.1
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.casimirlab.simpleDeadlines/com.casimirlab.simpleDeadlines.ui.MainActivity}: java.lang.IllegalStateException: Fragment DeadlineListFragment{ad2ef970} not attached to Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Fragment DeadlineListFragment{ad2ef970} not attached to Activity
at android.support.v4.app.Fragment.getLoaderManager(Fragment.java:881)
at com.casimirlab.simpleDeadlines.ui.DeadlineListFragment.setGroupFilter(DeadlineListFragment.java:178)
at com.casimirlab.simpleDeadlines.ui.MainActivity$2.onPageSelected(MainActivity.java:85)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:548)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:514)
at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1287)
at android.view.View.dispatchRestoreInstanceState(View.java:12284)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2620)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2626)
at android.view.View.restoreHierarchyState(View.java:12262)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1647)
at android.app.Activity.onRestoreInstanceState(Activity.java:938)
at android.app.Activity.performRestoreInstanceState(Activity.java:910)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2189)

@lingling-fan
Copy link
Author

package name: com.casimirlab.simpleDeadlines
version: 3.2.1
Exception: java.lang.IllegalStateException: Fragment DeadlineListFragment{ad2ef970} not attached to Activity
Category: Lifecycle
Description: When doing time-consuming operation in background thread(e.g, AsyncTask), a new Fragment has been created in the meantime, and was detached to the Activity before the background thread finished. The code in UI thread(e.g.,onPostExecute) calls upon a detached Fragment, throwing such exception.
Fix solution:
1: Cancel the background thread when pausing or stopping the Fragment
2: Use isAdded() to check whether the fragment is attached and then to getResources() from activity.

I'm looking forward to your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant