Skip to content

Commit

Permalink
Fix sonarcloud issue (deprecated onBackPressed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keidan committed Mar 29, 2024
1 parent 78bee44 commit 98eefca
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 98eefca

Please sign in to comment.