[Settings] Do not use deprecated API, onBackPressed
Bug: 318313238 Test: manual Change-Id: I616ea3cf4b2b89905d85380305df4853d4d5d626
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.localepicker;
|
||||
|
||||
import static android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT;
|
||||
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -23,6 +25,7 @@ import android.os.LocaleList;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.window.OnBackInvokedCallback;
|
||||
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
@@ -39,6 +42,10 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
||||
|
||||
private LocalePickerWithRegion mSelector;
|
||||
|
||||
private final OnBackInvokedCallback mOnBackInvokedCallback = () -> {
|
||||
handleBackPressed();
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -52,7 +59,8 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
||||
: bundle.getParcelable(Settings.EXTRA_EXPLICIT_LOCALES, LocaleList.class);
|
||||
Log.i(TAG, "Has explicit locales : " + explicitLocales);
|
||||
}
|
||||
|
||||
getOnBackInvokedDispatcher()
|
||||
.registerOnBackInvokedCallback(PRIORITY_DEFAULT, mOnBackInvokedCallback);
|
||||
mSelector = LocalePickerWithRegion.createLanguagePicker(
|
||||
this,
|
||||
LocalePickerWithRegionActivity.this,
|
||||
@@ -68,6 +76,12 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mOnBackInvokedCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
@@ -85,11 +99,6 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
handleBackPressed();
|
||||
}
|
||||
|
||||
private void handleBackPressed() {
|
||||
if (getFragmentManager().getBackStackEntryCount() > 1) {
|
||||
super.onBackPressed();
|
||||
|
Reference in New Issue
Block a user