-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Issue/fix lifecycle crash with appcompat 1 1 0 #11292
Issue/fix lifecycle crash with appcompat 1 1 0 #11292
Conversation
…WordPress-Android into issue/fix-lifecycle-crash-with-appcompat-1-1-0
Generated by 🚫 dangerJS |
You can test the changes on this Pull Request by downloading the APK here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crash happens when we try to access a fragment's layout in onSaveInstanceState during configuration change, while it's in a backstack. I have a feeling we were using the lifecycle bug as a feature :)
AFAIU the changes in the support library, we basically can't rely on any of "onCreateView, onStart, onResume, onPause, onStop," being invoked before onSaveInstanceState
, right? So technically if we for example initialize a field in onResume
and we want to save that field in onSaveInstanceState
, we need to check it's not null, correct?
I think this was never a bug in the lifecycle. Even the documentation states that onStop is invoked before onSaveInstanceState
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().
They just decided to change this behavior now, since they can't manage ViewModelStores without it. (btw another great decision - making the lifecycle even more complicated is the way to go :D)
But I guess it doesn't matter. The important part is that they are changing this behavior intentionally -> they plan to keep it.
I'm targeting this fix towards the feature branch, since develop branch will need other changes related to migration to the new appcompat library.
Can you please elaborate on the "other changes" part to make sure we are on the same page, thanks!
With Login Flow, we were trying to preserve the state of Gravatar loading progress. I don't think we need to do it since the progress indicator is visible when the view is created and is hidden when Glide loads cashed image or request fails. All this happens in onCreateView and we don't need to toggle it manually.
👍 I believe you are right;)
With Site Creation flow, I removed the explicit saving/restoring of the LinearLayoutManager. I don't have enough context to assume what it was used for, but I assume to preserve the scrolling state? If so it's already preserved during a normal configuration change. If it's something else, maybe @malinajirka can correct me.
Yeah, I believe that was the reason for this logic. If I recall correctly LayourManager didn't save it's state some time ago. It apparently does now, so I agree we can just remove the saving logic.
I have reviewed the code and it LGTM. I tested the site creation flow and the "magic link request" screen and they work as intended. Thanks @khaykov !
Since I didn't look into |
@malinajirka thanks for confirming the behavior!
Yes, we can only rely on
Sure, there are some semantical changes in method signatures and nullability of variables. I believe this closed PR has all of them. |
My understanding based on @marecar3 bug report was that the difference between 1.0.0 and 1.1.0 is that
Either case, I don't think it changes anything. I just want to understand the new behavior. I'll double check other onSaveInstanceState methods to increase the chance that we don't miss anything. |
I've tried to go over all the places where we add a fragment to the fragments back stack. It's almost impossible to review all the places. For example the app can crash on double rotation wherever we show FullScreenDialogFragment - if the fragment over which is the dialog shown touches views/adapters in the onSaveInstanceState.
:head-explode: |
I'm also trying to wrap my head around this problem, and there is one thing that bothers me - when you add a fragment to back stack, it goes through the lifecycle until |
Tbh I'm not sure how the OS behaves when you add a fragment into WordPress-Android/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java Line 211 in 97fe60b
I'm not sure I follow, but |
I tested the behavior of
So adding the transaction to backstack does not affect the underlying fragment. So even if we add the
When you add a fragment to backstack |
Ohh, thanks for the clarification! LGTM! ;) |
Related to #9905
CC @oguzkocer @malinajirka @marecar3
This PR fixes a couple of crashes that resulted from a change in fragment lifecycle behavior introduced in
appcompat
1.1.0.I'm targeting this fix towards the feature branch, since develop branch will need other changes related to migration to the new appcompat library.
The crash happens when we try to access a fragment's layout in
onSaveInstanceState
during configuration change, while it's in a backstack. I have a feeling we were using the lifecycle bug as a feature :)Luckily, I was only able to find two places where we do this - in Login and Site Creation flows.
After looking at the code that causes all this jazz, I made a conclusion that it might be redundant, and here is why:
With Login Flow, we were trying to preserve the state of Gravatar loading progress. I don't think we need to do it since the progress indicator is visible when the view is created and is hidden when Glide loads cashed image or request fails. All this happens in
onCreateView
and we don't need to toggle it manually.With Site Creation flow, I removed the explicit saving/restoring of the LinearLayoutManager. I don't have enough context to assume what it was used for, but I assume to preserve the scrolling state? If so it's already preserved during a normal configuration change. If it's something else, maybe @malinajirka can correct me.
If you think you might know other places where this issue might happen, please let me know!
To test (Login):
To test (Site Creation):
PR submission checklist:
RELEASE-NOTES.txt
if necessary.