From bd0282a0d797c5e747dffb18692702832350eab1 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Thu, 5 May 2022 16:45:57 +0000 Subject: [PATCH] [User Switcher] Remove callback in onDestroy Remove callback in onDestroy Bug: 230606671 Test: Manual on device Change-Id: I28be136d6617bbf5d09740dd051429e948cec9a1 --- .../android/systemui/user/UserSwitcherActivity.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt index 3329eabc80ad8..ad734914170b7 100644 --- a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt @@ -71,6 +71,11 @@ class UserSwitcherActivity @Inject constructor( private var popupMenu: UserSwitcherPopupMenu? = null private lateinit var addButton: View private var addUserRecords = mutableListOf() + private val userSwitchedCallback: UserTracker.Callback = object : UserTracker.Callback { + override fun onUserChanged(newUser: Int, userContext: Context) { + finish() + } + } // When the add users options become available, insert another option to manage users private val manageUserRecord = UserRecord( null /* info */, @@ -215,11 +220,7 @@ class UserSwitcherActivity @Inject constructor( initBroadcastReceiver() parent.post { buildUserViews() } - userTracker.addCallback(object : UserTracker.Callback { - override fun onUserChanged(newUser: Int, userContext: Context) { - finish() - } - }, mainExecutor) + userTracker.addCallback(userSwitchedCallback, mainExecutor) } private fun showPopupMenu() { @@ -340,6 +341,7 @@ class UserSwitcherActivity @Inject constructor( super.onDestroy() broadcastDispatcher.unregisterReceiver(broadcastReceiver) + userTracker.removeCallback(userSwitchedCallback) } private fun initBroadcastReceiver() {