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 {