Commit a3ae9dac authored by Ludovic Fauvet's avatar Ludovic Fauvet

Always call the supermethod before doing any work in the lifecycle methods

According to the documentation the implementation of these lifecycle
methods must always call the superclass implementation before doing any
work.

https://developer.android.com/guide/components/activities.html#ImplementingLifecycleCallbacks
parent 54278b77
...@@ -187,8 +187,8 @@ public class AudioService extends Service { ...@@ -187,8 +187,8 @@ public class AudioService extends Service {
@Override @Override
public void onDestroy() { public void onDestroy() {
unregisterReceiver(serviceReceiver);
super.onDestroy(); super.onDestroy();
unregisterReceiver(serviceReceiver);
} }
@Override @Override
......
...@@ -60,8 +60,8 @@ public class BrowserActivity extends ListActivity { ...@@ -60,8 +60,8 @@ public class BrowserActivity extends ListActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.browser);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.browser);
mAdapter = new BrowserAdapter(this); mAdapter = new BrowserAdapter(this);
setListAdapter(mAdapter); setListAdapter(mAdapter);
...@@ -80,9 +80,9 @@ public class BrowserActivity extends ListActivity { ...@@ -80,9 +80,9 @@ public class BrowserActivity extends ListActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy();
mAdapter.clear(); mAdapter.clear();
mScollStates.clear(); mScollStates.clear();
super.onDestroy();
} }
private void openDir(File file) { private void openDir(File file) {
......
...@@ -34,6 +34,7 @@ public class CompatErrorActivity extends Activity { ...@@ -34,6 +34,7 @@ public class CompatErrorActivity extends Activity {
*/ */
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.not_compatible); setContentView(R.layout.not_compatible);
String errorMsg = Util.getErrorMsg(); String errorMsg = Util.getErrorMsg();
...@@ -47,8 +48,6 @@ public class CompatErrorActivity extends Activity { ...@@ -47,8 +48,6 @@ public class CompatErrorActivity extends Activity {
TextView tv = (TextView)findViewById(R.id.errormsg); TextView tv = (TextView)findViewById(R.id.errormsg);
tv.setText(getResources().getString(R.string.error_message_is) + "\n" + errorMsg); tv.setText(getResources().getString(R.string.error_message_is) + "\n" + errorMsg);
super.onCreate(savedInstanceState);
//AsyncHttpRequest asyncHttpRequest = new AsyncHttpRequest(); //AsyncHttpRequest asyncHttpRequest = new AsyncHttpRequest();
//asyncHttpRequest.execute(Build.MODEL, Build.DEVICE); //asyncHttpRequest.execute(Build.MODEL, Build.DEVICE);
} }
......
...@@ -110,9 +110,10 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -110,9 +110,10 @@ public class MainActivity extends SherlockFragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!Util.hasCompatibleCPU()) { if (!Util.hasCompatibleCPU()) {
Log.e(TAG, Util.getErrorMsg()); Log.e(TAG, Util.getErrorMsg());
super.onCreate(savedInstanceState);
Intent i = new Intent(this, CompatErrorActivity.class); Intent i = new Intent(this, CompatErrorActivity.class);
startActivity(i); startActivity(i);
finish(); finish();
...@@ -166,7 +167,6 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -166,7 +167,6 @@ public class MainActivity extends SherlockFragmentActivity {
LibVLC.getInstance(); LibVLC.getInstance();
} catch (LibVlcException e) { } catch (LibVlcException e) {
e.printStackTrace(); e.printStackTrace();
super.onCreate(null);
Intent i = new Intent(this, CompatErrorActivity.class); Intent i = new Intent(this, CompatErrorActivity.class);
i.putExtra("runtimeError", true); i.putExtra("runtimeError", true);
i.putExtra("message", "LibVLC failed to initialize (LibVlcException)"); i.putExtra("message", "LibVLC failed to initialize (LibVlcException)");
...@@ -175,8 +175,6 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -175,8 +175,6 @@ public class MainActivity extends SherlockFragmentActivity {
return; return;
} }
super.onCreate(savedInstanceState);
/* Initialize UI variables */ /* Initialize UI variables */
mInfoLayout = v_main.findViewById(R.id.info_layout); mInfoLayout = v_main.findViewById(R.id.info_layout);
mInfoProgress = (ProgressBar) v_main.findViewById(R.id.info_progress); mInfoProgress = (ProgressBar) v_main.findViewById(R.id.info_progress);
...@@ -279,6 +277,7 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -279,6 +277,7 @@ public class MainActivity extends SherlockFragmentActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume();
mAudioController.addAudioPlayer(mAudioPlayer); mAudioController.addAudioPlayer(mAudioPlayer);
AudioServiceController.getInstance().bindAudioService(this); AudioServiceController.getInstance().bindAudioService(this);
...@@ -313,8 +312,6 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -313,8 +312,6 @@ public class MainActivity extends SherlockFragmentActivity {
/* Load media items from database and storage */ /* Load media items from database and storage */
if (mScanNeeded) if (mScanNeeded)
MediaLibrary.getInstance(this).loadMediaItems(this); MediaLibrary.getInstance(this).loadMediaItems(this);
super.onResume();
} }
/** /**
...@@ -322,6 +319,8 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -322,6 +319,8 @@ public class MainActivity extends SherlockFragmentActivity {
*/ */
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause();
/* Check for an ongoing scan that needs to be resumed during onResume */ /* Check for an ongoing scan that needs to be resumed during onResume */
mScanNeeded = MediaLibrary.getInstance(this).isWorking(); mScanNeeded = MediaLibrary.getInstance(this).isWorking();
/* Stop scanning for files */ /* Stop scanning for files */
...@@ -334,11 +333,12 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -334,11 +333,12 @@ public class MainActivity extends SherlockFragmentActivity {
editor.commit(); editor.commit();
mAudioController.removeAudioPlayer(mAudioPlayer); mAudioController.removeAudioPlayer(mAudioPlayer);
super.onPause();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy();
try { try {
unregisterReceiver(messageReceiver); unregisterReceiver(messageReceiver);
} catch (IllegalArgumentException e) {} } catch (IllegalArgumentException e) {}
......
...@@ -196,13 +196,13 @@ public class PreferencesActivity extends PreferenceActivity { ...@@ -196,13 +196,13 @@ public class PreferencesActivity extends PreferenceActivity {
@Override @Override
protected void onResume() { protected void onResume() {
AudioServiceController.getInstance().bindAudioService(this);
super.onResume(); super.onResume();
AudioServiceController.getInstance().bindAudioService(this);
} }
@Override @Override
protected void onPause() { protected void onPause() {
AudioServiceController.getInstance().unbindAudioService(this);
super.onPause(); super.onPause();
AudioServiceController.getInstance().unbindAudioService(this);
} }
} }
...@@ -89,21 +89,21 @@ public class SearchActivity extends ListActivity { ...@@ -89,21 +89,21 @@ public class SearchActivity extends ListActivity {
@Override @Override
protected void onResume() { protected void onResume() {
AudioServiceController.getInstance().bindAudioService(this);
super.onResume(); super.onResume();
AudioServiceController.getInstance().bindAudioService(this);
} }
@Override @Override
protected void onPause() { protected void onPause() {
AudioServiceController.getInstance().unbindAudioService(this);
super.onPause(); super.onPause();
AudioServiceController.getInstance().unbindAudioService(this);
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy();
mHistoryAdapter.clear(); mHistoryAdapter.clear();
mResultAdapter.clear(); mResultAdapter.clear();
super.onDestroy();
} }
private void search(CharSequence key, int type) { private void search(CharSequence key, int type) {
......
...@@ -332,11 +332,11 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable ...@@ -332,11 +332,11 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy();
mSongsAdapter.clear(); mSongsAdapter.clear();
mArtistsAdapter.clear(); mArtistsAdapter.clear();
mAlbumsAdapter.clear(); mAlbumsAdapter.clear();
mGenresAdapter.clear(); mGenresAdapter.clear();
super.onDestroy();
} }
private final ViewSwitchListener mViewSwitchListener = new ViewSwitchListener() { private final ViewSwitchListener mViewSwitchListener = new ViewSwitchListener() {
......
...@@ -111,8 +111,8 @@ public class AudioListFragment extends SherlockListFragment { ...@@ -111,8 +111,8 @@ public class AudioListFragment extends SherlockListFragment {
@Override @Override
public void onDestroy() { public void onDestroy() {
mSongsAdapter.clear();
super.onDestroy(); super.onDestroy();
mSongsAdapter.clear();
} }
public static void set(Intent intent, String name, String name2, int mode) { public static void set(Intent intent, String name, String name2, int mode) {
......
...@@ -101,16 +101,16 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer { ...@@ -101,16 +101,16 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume();
AudioServiceController.getInstance().bindAudioService(this); AudioServiceController.getInstance().bindAudioService(this);
mAudioController.addAudioPlayer(this); mAudioController.addAudioPlayer(this);
super.onResume();
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause();
mAudioController.removeAudioPlayer(this); mAudioController.removeAudioPlayer(this);
AudioServiceController.getInstance().unbindAudioService(this); AudioServiceController.getInstance().unbindAudioService(this);
super.onPause();
} }
public static void start(Context context) { public static void start(Context context) {
......
...@@ -126,6 +126,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable ...@@ -126,6 +126,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
//Get & highlight the last media //Get & highlight the last media
SharedPreferences preferences = getActivity().getSharedPreferences(PreferencesActivity.NAME, Context.MODE_PRIVATE); SharedPreferences preferences = getActivity().getSharedPreferences(PreferencesActivity.NAME, Context.MODE_PRIVATE);
String lastPath = preferences.getString(PreferencesActivity.LAST_MEDIA, null); String lastPath = preferences.getString(PreferencesActivity.LAST_MEDIA, null);
...@@ -133,7 +134,6 @@ public class VideoListFragment extends SherlockListFragment implements ISortable ...@@ -133,7 +134,6 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
mVideoAdapter.setLastMedia(lastPath, times); mVideoAdapter.setLastMedia(lastPath, times);
mVideoAdapter.notifyDataSetChanged(); mVideoAdapter.notifyDataSetChanged();
mMediaLibrary.addUpdateHandler(mHandler); mMediaLibrary.addUpdateHandler(mHandler);
super.onResume();
} }
@Override @Override
...@@ -144,9 +144,9 @@ public class VideoListFragment extends SherlockListFragment implements ISortable ...@@ -144,9 +144,9 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy();
mBarrier.reset(); mBarrier.reset();
mVideoAdapter.clear(); mVideoAdapter.clear();
super.onDestroy();
} }
@Override @Override
......
...@@ -316,10 +316,11 @@ public class VideoPlayerActivity extends Activity { ...@@ -316,10 +316,11 @@ public class VideoPlayerActivity extends Activity {
@Override @Override
protected void onPause() { protected void onPause() {
if(mSwitchingView) { super.onPause();
super.onPause();
if(mSwitchingView)
return; return;
}
long time = mLibVLC.getTime(); long time = mLibVLC.getTime();
long length = mLibVLC.getLength(); long length = mLibVLC.getLength();
//remove saved position if in the last 5 seconds //remove saved position if in the last 5 seconds
...@@ -358,11 +359,11 @@ public class VideoPlayerActivity extends Activity { ...@@ -358,11 +359,11 @@ public class VideoPlayerActivity extends Activity {
DatabaseManager.mediaColumn.MEDIA_TIME, DatabaseManager.mediaColumn.MEDIA_TIME,
time); time);
} }
super.onPause();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mBatteryReceiver); unregisterReceiver(mBatteryReceiver);
if (mLibVLC != null && !mSwitchingView) { if (mLibVLC != null && !mSwitchingView) {
mLibVLC.stop(); mLibVLC.stop();
...@@ -379,11 +380,11 @@ public class VideoPlayerActivity extends Activity { ...@@ -379,11 +380,11 @@ public class VideoPlayerActivity extends Activity {
AudioPlayerActivity.start(this, true); AudioPlayerActivity.start(this, true);
} }
//AudioServiceController.getInstance().unbindAudioService(this); //AudioServiceController.getInstance().unbindAudioService(this);
super.onDestroy();
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume();
AudioServiceController.getInstance().bindAudioService(this); AudioServiceController.getInstance().bindAudioService(this);
load(); load();
...@@ -404,8 +405,6 @@ public class VideoPlayerActivity extends Activity { ...@@ -404,8 +405,6 @@ public class VideoPlayerActivity extends Activity {
}}, 500); }}, 500);
showOverlay(); showOverlay();
super.onResume();
} }
@Override @Override
...@@ -863,7 +862,7 @@ public class VideoPlayerActivity extends Activity { ...@@ -863,7 +862,7 @@ public class VideoPlayerActivity extends Activity {
getWindow().setAttributes(lp); getWindow().setAttributes(lp);
mIsFirstBrightnessGesture = false; mIsFirstBrightnessGesture = false;
} }
private void doBrightnessTouch(float gesturesize) { private void doBrightnessTouch(float gesturesize) {
// No Brightness action if gesturesize < 0.4 cm // No Brightness action if gesturesize < 0.4 cm
if (Math.abs(gesturesize) < 0.4) if (Math.abs(gesturesize) < 0.4)
......
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