[Android] Handle backstack navigation in preferences

Geoffrey Métais git at videolan.org
Tue Oct 20 11:48:31 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Oct 20 11:41:02 2015 +0200| [2fff04889ededf7b5e3dc9d00730671c3260a725] | committer: Geoffrey Métais

Handle backstack navigation in preferences

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2fff04889ededf7b5e3dc9d00730671c3260a725
---

 .../vlc/gui/preferences/PreferencesActivity.java     |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
index 37f6773..3a31c51 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
@@ -24,8 +24,10 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
+import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.Toolbar;
+import android.view.MenuItem;
 
 import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
@@ -59,15 +61,15 @@ public class PreferencesActivity extends AppCompatActivity implements PlaybackSe
 
         setContentView(R.layout.preferences_activity);
         setSupportActionBar((Toolbar) findViewById(R.id.main_toolbar));
+        getSupportFragmentManager().beginTransaction()
+                .add(R.id.fragment_placeholder, new PreferencesFragment())
+                .commit();
     }
 
     @Override
     protected void onStart() {
         super.onStart();
         mClient.connect();
-        getSupportFragmentManager().beginTransaction()
-                .add(R.id.fragment_placeholder, new PreferencesFragment())
-                .commit();
     }
 
     @Override
@@ -76,6 +78,16 @@ public class PreferencesActivity extends AppCompatActivity implements PlaybackSe
         mClient.disconnect();
     }
 
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        if (item.getItemId() == android.R.id.home) {
+            if (!getSupportFragmentManager().popBackStackImmediate())
+                finish();
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
     private void applyTheme() {
         SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
         boolean enableBlackTheme = pref.getBoolean("enable_black_theme", false);



More information about the Android mailing list