[Android] Fix a random NullPointerException in menu creation
Ludovic Fauvet
git at videolan.org
Thu Jun 28 18:04:56 CEST 2012
android | branch: master | Ludovic Fauvet <etix at videolan.org> | Thu Jun 28 18:03:15 2012 +0200| [934f6342326d9e7bc9c985011a734c4bf56b06cb] | committer: Ludovic Fauvet
Fix a random NullPointerException in menu creation
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=934f6342326d9e7bc9c985011a734c4bf56b06cb
---
.../src/org/videolan/vlc/gui/MainActivity.java | 23 ++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index d355030..91d45a9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -170,6 +170,9 @@ public class MainActivity extends SherlockFragmentActivity {
filter.addAction(ACTION_SHOW_TEXTINFO);
registerReceiver(messageReceiver, filter);
+ /* Reload the latest preferences */
+ reloadPreferences();
+
/* Load media items from database and storage */
MediaLibrary.getInstance(this).loadMediaItems(this);
}
@@ -178,10 +181,6 @@ public class MainActivity extends SherlockFragmentActivity {
protected void onResume() {
mAudioController.addAudioPlayer(mAudioPlayer);
AudioServiceController.getInstance().bindAudioService(this);
-
- SharedPreferences sharedPrefs = getSharedPreferences("MainActivity", MODE_PRIVATE);
- mCurrentViewTab = sharedPrefs.getInt("tab", VIDEO_TAB);
- mMediaLibraryActive = sharedPrefs.getBoolean("medialibrary", true);
Boolean startFromNotification = getIntent().hasExtra(AudioService.START_FROM_NOTIFICATION);
/* Restore last view */
@@ -215,10 +214,20 @@ public class MainActivity extends SherlockFragmentActivity {
super.onDestroy();
}
+ @Override
+ protected void onRestart() {
+ /* Reload the latest preferences */
+ reloadPreferences();
+ }
+
/** Create menu from XML
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
+ /* Note: on Android 3.0+ with an action bar this method
+ * is called while the view is created. This can happen
+ * any time after onCreate.
+ */
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.media_library, menu);
MenuItem browse = menu.findItem(R.id.ml_menu_browse);
@@ -296,6 +305,12 @@ public class MainActivity extends SherlockFragmentActivity {
return super.onOptionsItemSelected(item);
}
+ private void reloadPreferences() {
+ SharedPreferences sharedPrefs = getSharedPreferences("MainActivity", MODE_PRIVATE);
+ mCurrentViewTab = sharedPrefs.getInt("tab", VIDEO_TAB);
+ mMediaLibraryActive = sharedPrefs.getBoolean("medialibrary", true);
+ }
+
private void showDirectoryView() {
FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
More information about the Android
mailing list