fennifith / Status

A no-root status bar replacement for Android.
https://play.google.com/store/apps/details?id=com.james.status
Apache License 2.0
127 stars 29 forks source link

crash when screen rotate #128

Closed muhammadarif1 closed 6 years ago

muhammadarif1 commented 6 years ago

EXPECTED BEHAVIOR

when users change the position of their phone screen users should still be able to use this app well

ACTUAL BEHAVIOR

  when the user changes the position of their phone screen then the user refresh the list of applications that will make the status, this application will crash.

HOW TO REPRODUCE

BUG RECORDING

https://youtu.be/Qq0BlYYk4sE

logcat file


Process: com.james.status, PID: 15853
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
    at com.james.status.fragments.AppPreferenceFragment.isNotifications(AppPreferenceFragment.java:120)
    at com.james.status.activities.MainActivity.onPageSelected(MainActivity.java:371)
    at android.support.v4.view.ViewPager.dispatchOnPageSelected(ViewPager.java:1967)
    at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:685)
    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:669)
    at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:2284)
    at android.view.View.dispatchTouchEvent(View.java:8484)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2103)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2438)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2132)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2438)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2132)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2438)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2132)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2438)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2132)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2438)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2132)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2438)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2132)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2424)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1768)
    at android.app.Activity.dispatchTo```
fennifith commented 6 years ago

Oh my god what on earth is happening here.

I originally couldn't reproduce the issue on my device, then after watching the recording (which was quite useful, thank you for including this much information with the report), I realized that for some reason your phone is completely ignoring the activity/fragment lifecycle. In other words, when you rotate your phone, the activity state is preserved (it shouldn't be, but that isn't really the issue here), and the fragment is recreated without calling onCreate, which initializes the list. The MainActivity then detects the swipe event and asks the fragment for information to update its overflow menu, causing it to iterate through a list that hasn't been initialized yet, and causing the crash. What the heck.

It's easy enough to add a null check for this, but this should never occur in the first place. Of course it would never happen if I hadn't implemented such a hacky method of adding stuff to an overflow menu in the first place (the fragment should get its info from the activity, not the other way around), but agh [insert rant about Android fragmentation here] [insert rant about crappy OEM skins here] I hate Android sometimes.