diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2018-04-29 10:14:20 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2018-04-30 17:30:24 +0530 |
commit | fe4cc22ca0e846d10658093dfe424753c95a24d4 (patch) | |
tree | 5435220213cf5c3a03800b8eabfb485bd2aa5672 /app | |
parent | 4fc1e61a83da771e484fa2ea4755da49e013e0fc (diff) |
SettingsActivity: Gracefully exit when options menu home is pressed
This is an activity, so it does not join the fragment backstack, but
instead piles on top
SettingsActivity
| -> MainActivity
| -> EditorFragment
| -> DetailFragment
| -> ListFragment
Without overriding the back button in the toolbar, it simply
kills the entire state on MainActivity and causes it to reload.
By calling finish() on the activity when home is pressed from the
item menu we can silently make it die without affecting any underlying
states held by MainActivity and instead return to the exact fragment
we launched settings from.
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/wireguard/android/activity/SettingsActivity.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java index 273c7da8..b1754b87 100644 --- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java @@ -6,6 +6,7 @@ import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; +import android.view.MenuItem; import com.wireguard.android.Application; import com.wireguard.android.R; @@ -75,6 +76,17 @@ public class SettingsActivity extends AppCompatActivity { } } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + public static class SettingsFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(final Bundle savedInstanceState, final String key) { |