From 98eefcadce8d2338ddd958c90d3792eadecb1d6b Mon Sep 17 00:00:00 2001 From: "Keidan (K. Billonneau)" Date: Fri, 29 Mar 2024 15:18:00 +0100 Subject: [PATCH] Fix sonarcloud issue (deprecated onBackPressed) --- .../ui/activities/AbstractBaseMainActivity.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/ralala/hexviewer/ui/activities/AbstractBaseMainActivity.java b/app/src/main/java/fr/ralala/hexviewer/ui/activities/AbstractBaseMainActivity.java index ee0f784..7aacd71 100644 --- a/app/src/main/java/fr/ralala/hexviewer/ui/activities/AbstractBaseMainActivity.java +++ b/app/src/main/java/fr/ralala/hexviewer/ui/activities/AbstractBaseMainActivity.java @@ -11,6 +11,7 @@ import android.view.View; import android.widget.SearchView; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; @@ -83,6 +84,13 @@ protected void onCreate(final Bundle savedInstanceState) { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, 1); + + getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + back(); + } + }); } protected void setSearchView(MenuItem si) { @@ -165,8 +173,7 @@ protected void cancelSearch() { /** * Called to handle the click on the back button. */ - @Override - public void onBackPressed() { + private void back() { if (mSearchView != null && !mSearchView.isIconified()) { cancelSearch(); } else {