- // Initialize the database handler. The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHelper`.
- bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0);
+ // Control what the system back command does.
+ OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
+ @Override
+ public void handleOnBackPressed() {
+ // Prepare to finish the activity.
+ prepareFinish();
+ }
+ };
+
+ // Register the on back pressed callback.
+ getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
+
+ // Initialize the database handler.
+ bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this);