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

NPE when MaterialIntroActivity restoring state #142

Open
gitanuj opened this issue Jan 25, 2018 · 1 comment
Open

NPE when MaterialIntroActivity restoring state #142

gitanuj opened this issue Jan 25, 2018 · 1 comment

Comments

@gitanuj
Copy link

gitanuj commented Jan 25, 2018

Steps:

  1. Enable "Don't keep activities" option in Developer Options
  2. Add a SlideFragment with hasNeededPermissionsToGrant() & hasAnyPermissionsToGrant() set to false
  3. Open the MaterialActivity with this fragment selected
  4. Send Activity to background
  5. Use recents menu to open the activity back

Looks like getActivity() is null at the moment. A simple fix could be to just ignore the call if it's null.

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tanuj.nowplayinghistory/com.tanuj.nowplayinghistory.activities.IntroActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.support.v4.app.FragmentActivity.getString(int)' on a null object reference android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2778) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2856) android.app.ActivityThread.-wrap11 () android.app.ActivityThread$H.handleMessage (ActivityThread.java:1589) android.os.Handler.dispatchMessage (Handler.java:106) android.os.Looper.loop (Looper.java:164) android.app.ActivityThread.main (ActivityThread.java:6494) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807) Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.support.v4.app.FragmentActivity.getString(int)' on a null object reference agency.tango.materialintroscreen.listeners.MessageButtonBehaviourOnPageSelected.pageSelected (MessageButtonBehaviourOnPageSelected.java:32) agency.tango.materialintroscreen.listeners.ViewBehavioursOnPageChangeListener.onPageSelected (ViewBehavioursOnPageChangeListener.java:61) android.support.v4.view.CustomViewPager.dispatchOnPageSelected (CustomViewPager.java:1939) android.support.v4.view.CustomViewPager.setCurrentItemInternal (CustomViewPager.java:666) android.support.v4.view.CustomViewPager.setCurrentItemInternal (CustomViewPager.java:632) android.support.v4.view.CustomViewPager.onRestoreInstanceState (CustomViewPager.java:1454) android.view.View.dispatchRestoreInstanceState (View.java:17706) android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:3745) android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:3751) android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:3751) android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:3751) android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:3751) android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:3751) android.view.View.restoreHierarchyState (View.java:17684) com.android.internal.policy.PhoneWindow.restoreHierarchyState (PhoneWindow.java:2131) android.app.Activity.onRestoreInstanceState (Activity.java:1102) android.app.Activity.performRestoreInstanceState (Activity.java:1057) android.app.Instrumentation.callActivityOnRestoreInstanceState (Instrumentation.java:1260) android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2751) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2856) android.app.ActivityThread.-wrap11 () android.app.ActivityThread$H.handleMessage (ActivityThread.java:1589) android.os.Handler.dispatchMessage (Handler.java:106) android.os.Looper.loop (Looper.java:164) android.app.ActivityThread.main (ActivityThread.java:6494) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)

@gitanuj
Copy link
Author

gitanuj commented Jan 25, 2018

For example it happens on the following fragment when user taps button to enable "Notification Access" which opens the Settings app. Then for some reason my app's Activity is removed from memory and user comes back to the Activity without enabling the permission.

https://github.com/gitanuj/nowplayinghistory/blob/master/app/src/main/java/com/tanuj/nowplayinghistory/fragments/NotificationAccessSlide.java

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

Successfully merging a pull request may close this issue.

1 participant