Commit 934f6342 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

Fix a random NullPointerException in menu creation

parent 634fc6b0
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment