moxy-community / Moxy

Moxy is MVP library for Android with incremental annotation processor and ktx features
MIT License
324 stars 33 forks source link

Behaviour on different Android versions #103

Closed progk closed 3 years ago

progk commented 4 years ago

Hi! I have various presenter behaviour on different Android versions because of MvpDelegate.onDetach call in MvpAppCompatFragment.onSaveInstanceState



MvpAppCompatFragment lifecycle callbacks after request permission:



Android 6 (API 23): …
 onResume
 (request permission)
 onPause
 onSavedInstanceState
 …



Android 10 (API 29): … 
onResume
 (request permission)
 onPause


In my app i use custom MvpFragment(with the same logic) and plan to remove onDetach from onSaveInstanceState. I see no reason not to do it. Could you explain please why this logic was added or provide cases of possible memory leaks?

bejibx commented 3 years ago

You could have problems if for example your presenter will call method which shows fragment using FragmentTransaction#commit() or FragmentTransaction#commitNow(). If you did not detach your MvpDelegate during onSavedInstanceState this method could get called after saving state which will lead to a app crash.

progk commented 3 years ago

Detach is also called in MvpAppCompatFragment.onStop. Should work fine in your case

bejibx commented 3 years ago

From the documentation (https://developer.android.com/reference/android/app/Activity#onSaveInstanceState(android.os.Bundle)):

If called, this method will occur after onStop() for applications targeting platforms starting with Build.VERSION_CODES.P. For applications targeting earlier platform versions this method will occur before onStop() and there are no guarantees about whether it will occur before or after onPause().

progk commented 3 years ago

Ok, i got it, thanks for explanation