YahooNewsOnboarding icon indicating copy to clipboard operation
YahooNewsOnboarding copied to clipboard

ScreenSlideFragment must be a public static class to be properly recreated from instance state.

Open alexspyr opened this issue 8 years ago • 4 comments

Hey, I came across a similar issue a while back and I resolved it by adding @SuppressLint("ValidFragment") before the ScreenSlideFragment class but now it came back. I think it's happening when I am changing the compiled compileSdkVersion. For what I gather from my research the problem is that it doesn't allow Android to create the same Fragment if the old one was deleted. Any help with how to proceed would be helpful. Full stack trace below.

` Fatal Exception: java.lang.IllegalStateException: Fragment example.com.example.SignupTutorial.ScreenSlideFragment must be a public static class to be properly recreated from instance state.

at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:384) at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:369) at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:123) at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1034) at android.support.v4.view.ViewPager.populate(ViewPager.java:1182) at android.support.v4.view.ViewPager.populate(ViewPager.java:1116) at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642) at android.view.View.measure(View.java:18804) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure(View.java:18804) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) at android.view.View.measure(View.java:18804) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) at android.widget.LinearLayout.measureVertical(LinearLayout.java:748) at android.widget.LinearLayout.onMeasure(LinearLayout.java:630) at android.view.View.measure(View.java:18804) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:18804) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) at android.widget.LinearLayout.measureVertical(LinearLayout.java:748) at android.widget.LinearLayout.onMeasure(LinearLayout.java:630) at android.view.View.measure(View.java:18804) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643) at android.view.View.measure(View.java:18804) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2112) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1228) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1464) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:746) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)`

alexspyr avatar Jan 20 '17 17:01 alexspyr

So I solved the problem by making all the classes and methods of this activity static and it worked. I don't know if that what I was suppose to do, but it worked that way.

alexspyr avatar Jan 20 '17 18:01 alexspyr

Close the issue if you think it's closed :)

alexspyr avatar Jan 20 '17 18:01 alexspyr

Okay. I think i will have to move that class to an external public class. I will do that and notify you. For now you can use the static way if that works fine.

rahulrj avatar Jan 22 '17 20:01 rahulrj

I have solved this issue that move my Fragment class from activity class and create one external class and use it. It working fine with me

aivision369 avatar Dec 14 '17 08:12 aivision369