federicoiosue / Omni-Notes

Open source note-taking application for Android
https://omninotes.app
GNU General Public License v3.0
2.68k stars 1.11k forks source link

App crash after two times device orientation changes #815

Closed tappdesign closed 3 years ago

tappdesign commented 3 years ago

Just open some existing note for edit. Rotate device two times (vertical - horizontal - vertical) and app will crash:

2021-01-26 13:50:48.026 23490-23490/it.feio.android.omninotes I/HwSecImmHelper: mSecurityInputMethodService is null
2021-01-26 13:50:48.034 23490-23490/it.feio.android.omninotes D/AndroidRuntime: Shutting down VM
2021-01-26 13:50:48.044 23490-23490/it.feio.android.omninotes E/AndroidRuntime: FATAL EXCEPTION: main
    Process: it.feio.android.omninotes, PID: 23490
    java.lang.NullPointerException: Attempt to read from field 'it.feio.android.omninotes.models.views.RecyclerViewEmptySupport it.feio.android.omninotes.databinding.FragmentListBinding.list' on a null object reference
        at it.feio.android.omninotes.ListFragment.refreshListScrollPosition(ListFragment.java:375)
        at it.feio.android.omninotes.ListFragment.onSaveInstanceState(ListFragment.java:366)
        at androidx.fragment.app.Fragment.performSaveInstanceState(Fragment.java:2863)
        at androidx.fragment.app.FragmentStateManager.saveBasicState(FragmentStateManager.java:434)
        at androidx.fragment.app.FragmentStateManager.saveState(FragmentStateManager.java:400)
        at androidx.fragment.app.FragmentStore.saveActiveFragments(FragmentStore.java:143)
        at androidx.fragment.app.FragmentManager.saveAllState(FragmentManager.java:2386)
        at androidx.fragment.app.FragmentController.saveAllState(FragmentController.java:152)
        at androidx.fragment.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:512)
        at androidx.appcompat.app.AppCompatActivity.onSaveInstanceState(AppCompatActivity.java:533)
        at it.feio.android.omninotes.MainActivity.onSaveInstanceState(MainActivity.java:318)
        at android.app.Activity.performSaveInstanceState(Activity.java:1615)
        at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1398)
        at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:5499)
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5450)
        at android.app.ActivityThread.-wrap19(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2000)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)

binding becomes null

possible fix in this commit: https://github.com/tappdesign/Omni-Notes/commit/148da101db91fb1f3728f30bd5b06937b0004462

as it is advised https://stackoverflow.com/questions/23391837/fragment-oncreateview-and-onactivitycreated-not-being-called-on-rotation

but I'm not sure if this is the right solution....

federicoiosue commented 3 years ago

Doing like that onDestroy will not be called, and could leak something (for example EventBus events will still be received)

fragment_lifecycle

I'm going to get the same change you made but trying keeping your app under observation for strange behaviors related to this.

federicoiosue commented 3 years ago

Just a reminder for me: this happens when rotating the detail fragment due to fragment stack containing a destroyed ListFragment