Skip to content

Commit

Permalink
Fix two taps needed to close the app from Settings view
Browse files Browse the repository at this point in the history
FLAG_ACTIVITY_NEW_TASK was incorrectly set, requiring pressing the
back button twice in order to close the app
  • Loading branch information
emanuele-f committed Aug 15, 2024
1 parent 9436f9e commit bc61c08
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,20 @@ public void onBackStackChanged() {
public void onBackPressed() {
Fragment f = getSupportFragmentManager().findFragmentById(R.id.settings_container);
if(f instanceof SettingsFragment) {
// Use a custom intent to provide "up" navigation after ACTION_LANG_RESTART took place
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
} else
super.onBackPressed();
Intent intent = getIntent();

if ((intent != null) && SettingsActivity.ACTION_LANG_RESTART.equals(intent.getAction())) {
// Use a custom intent to provide "up" navigation after ACTION_LANG_RESTART took place
intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
return;
}
}

// default behavior
super.onBackPressed();
}

public static class SettingsFragment extends PreferenceFragmentCompat {
Expand Down

0 comments on commit bc61c08

Please sign in to comment.