Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit ab695aa607c404faddb85a9d232416bd0c62bd52
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Sep 16 11:41:14 2021
Ensure we remove observers when removing menu Providers
If you add a MenuProvider using a Lifecycle owner, then call
removeMenuProvider before the Lifeycycle reaches DESTROYED, the observer
is never removed so there is an unneeded additional call to
removeMenuProvider that also invalidates the menu again.
We need to track all of the added observers and ensure they are also
removed when the call to removeMenuProvider is made.
RelNote: "MenuHostHelper will now properly remove all LifecycleObservers
when a MenuProvider is removed prior to the Lifecycle being DESTROYED."
Test: added MenuHostHelperTest
Bug: 199788262
Change-Id: Ibe2e1f4a29c8079549814aaaa9b2484c22a41b2e
M core/core/src/androidTest/java/androidx/core/view/MenuHostTest.kt
M core/core/src/androidTest/java/androidx/core/view/MenuHostHelperTest.kt
M core/core/src/main/java/androidx/core/view/MenuHostHelper.java
https://android-review.googlesource.com/1828509
Branch: androidx-main
commit ab695aa607c404faddb85a9d232416bd0c62bd52
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Sep 16 11:41:14 2021
Ensure we remove observers when removing menu Providers
If you add a MenuProvider using a Lifecycle owner, then call
removeMenuProvider before the Lifeycycle reaches DESTROYED, the observer
is never removed so there is an unneeded additional call to
removeMenuProvider that also invalidates the menu again.
We need to track all of the added observers and ensure they are also
removed when the call to removeMenuProvider is made.
RelNote: "MenuHostHelper will now properly remove all LifecycleObservers
when a MenuProvider is removed prior to the Lifecycle being DESTROYED."
Test: added MenuHostHelperTest
Bug: 199788262
Change-Id: Ibe2e1f4a29c8079549814aaaa9b2484c22a41b2e
M core/core/src/androidTest/java/androidx/core/view/MenuHostTest.kt
M core/core/src/androidTest/java/androidx/core/view/MenuHostHelperTest.kt
M core/core/src/main/java/androidx/core/view/MenuHostHelper.java
jb...@google.com <jb...@google.com> #3
This has been fixed internally and will be available in the Activity 1.4.0-alpha03
release.
Description
Component used: Core
Version used: 1.7.0-alpha02. Also affects Activity
1.4.0-alpha01
and up.When using the
addMenuProvider
methods that take aLifecycle
, callingremoveMenuProvider
doesn't actually remove the underlyingLifecycleObserver
thatMenuHostHelper
adds.This has a couple of implications:
removeMenuProvider
is called when the Lifecycle is below the givenstate
,removeMenuProvider
doesn't remove theMenuProvider
and when the Lifecycle reaches the given state, it still gets addedremoveMenuProvider
is called when the Lifecycle is above the givenstate
,removeMenuProvider
does remove theMenuProvider
, but if the Lifecycle goes down and then back up again, it gets re-added.ActivityResultRegistry
handles these cases (register
with aLifecycleOwner
, then callingunregister
) byLifecycleOwner
+LifecycleObserver
instancesMenuProvider
as the key.