FadeableViewPager OnPageChangeListener called before fragment views are restored after onRestoreInstanceState
MFlisar opened this issue · 0 comments
MFlisar commented
If the activity is recreated I see following behaviour:
SwipeBlockableViewPager
restores its state and calls onPageSelected
of its page selected callback. Inside this callback I can't yet get the current fragment's views yet which I need to do to update the pages texts correctly...
I'm using the master build.
Code
My code looks like following:
@Override
public void onPageSelected(int position) {
SimpleSlide.SimpleSlideFragment slide = ((SimpleSlide.SimpleSlideFragment) getItem(position));
Long id = ((SimpleSlide.SimpleSlideFragment) getItem(position)).getSlideId();
int intId = id.intValue();
if (intId == R.string.setup_slide6_title) {
updatePermissionStatePage(slide);
}
}
private void updatePermissionStatePage(SimpleSlide.SimpleSlideFragment fragment) {
boolean overlayPermission = Permission.DrawOverlay.isPermissionGranted();
// THIS LINE CRASHES
fragment.getTitleView().setText(overlayPermission ? R.string.setup_slide6_title : R.string.setup_slide5_title);
fragment.getDescriptionView().setText(overlayPermission ? R.string.setup_slide6_text :
}
Stacktrace
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(int)' on a null object reference
at com.my.app.ui.activitiesandfragments.SetupActivity.a(SetupActivity.java:245)
at com.my.app.ui.activitiesandfragments.SetupActivity.a(SetupActivity.java:203)
at com.heinrichreimersoftware.materialintro.view.FadeableViewPager$OnPageChangeListenerWrapper.a(FadeableViewPager.java:99)
at androidx.viewpager.widget.ViewPager.e(ViewPager.java:1947)
at androidx.viewpager.widget.ViewPager.a(ViewPager.java:665)
at androidx.viewpager.widget.ViewPager.a(ViewPager.java:631)
at androidx.viewpager.widget.ViewPager.onRestoreInstanceState(ViewPager.java:1462)
at com.heinrichreimersoftware.materialintro.view.SwipeBlockableViewPager.onRestoreInstanceState(SwipeBlockableViewPager.java:171)
at android.view.View.dispatchRestoreInstanceState(View.java:14835)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3174)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3180)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3180)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3180)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3180)
at android.view.View.restoreHierarchyState(View.java:14813)
at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2062)
at android.app.Activity.onRestoreInstanceState(Activity.java:1009)
at android.app.Activity.performRestoreInstanceState(Activity.java:964)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1164)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
... 9 more