[Android] Use onStart/onStop instead of onResume/onPause

Geoffrey Métais git at videolan.org
Wed Aug 23 18:17:38 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug 23 11:13:55 2017 +0200| [55382edadc845608a3b9e3be875347d646c05478] | committer: Geoffrey Métais

Use onStart/onStop instead of onResume/onPause

> https://code.videolan.org/videolan/vlc-android/commit/55382edadc845608a3b9e3be875347d646c05478
---

 .../src/org/videolan/vlc/gui/MainActivity.java     | 69 ++++++++--------------
 1 file changed, 26 insertions(+), 43 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index fa29aeebe..dfe6df4ca 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -251,11 +251,37 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
     @Override
     protected void onStart() {
         super.onStart();
+        mCurrentFragmentId = mSettings.getInt("fragment_id", R.id.nav_video);
+        if (mMediaLibrary.isInitiated()) {
+            /* Load media items from database and storage */
+            if (mScanNeeded && Permissions.canReadStorage())
+                startService(new Intent(MediaParsingService.ACTION_RELOAD, null,this, MediaParsingService.class));
+            else if (!currentIdIsExtension())
+                restoreCurrentList();
+        }
+        mNavigationView.setNavigationItemSelectedListener(this);
+        if (BuildConfig.DEBUG)
+            createExtensionServiceConnection();
     }
 
     @Override
     protected void onStop() {
         super.onStop();
+        mNavigationView.setNavigationItemSelectedListener(null);
+        if (getChangingConfigurations() == 0) {
+            /* Check for an ongoing scan that needs to be resumed during onResume */
+            mScanNeeded = mMediaLibrary.isWorking();
+        }
+        /* Save the tab status in pref */
+        mSettings.edit().putInt("fragment_id", mCurrentFragmentId).apply();
+        if (mExtensionServiceConnection != null) {
+            unbindService(mExtensionServiceConnection);
+            mExtensionServiceConnection = null;
+        }
+        if (currentIdIsExtension())
+            mSettings.edit()
+                    .putString("current_extension_name", mExtensionsManager.getExtensions(getApplication(), false).get(mCurrentFragmentId).componentName().getPackageName())
+                    .apply();
     }
 
     private void loadPlugins() {
@@ -293,14 +319,12 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
 
     private void createExtensionServiceConnection() {
         mExtensionServiceConnection = new ServiceConnection() {
-
             @Override
             public void onServiceConnected(ComponentName name, IBinder service) {
                 mExtensionManagerService = ((ExtensionManagerService.LocalBinder)service).getService();
                 mExtensionManagerService.setExtensionManagerActivity(MainActivity.this);
                 loadPlugins();
             }
-
             @Override
             public void onServiceDisconnected(ComponentName name) {}
         };
@@ -311,23 +335,6 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
     }
 
     @Override
-    protected void onResume() {
-        super.onResume();
-        if (BuildConfig.DEBUG)
-            createExtensionServiceConnection();
-        mCurrentFragmentId = mSettings.getInt("fragment_id", R.id.nav_video);
-        if (mMediaLibrary.isInitiated()) {
-            /* Load media items from database and storage */
-            if (mScanNeeded && Permissions.canReadStorage())
-                startService(new Intent(MediaParsingService.ACTION_RELOAD, null,this, MediaParsingService.class));
-            else
-                if (!currentIdIsExtension())
-                    restoreCurrentList();
-        }
-        mNavigationView.setNavigationItemSelectedListener(this);
-    }
-
-    @Override
     protected void onResumeFragments() {
         super.onResumeFragments();
         mCurrentFragmentId = mSettings.getInt("fragment_id", R.id.nav_video);
@@ -335,30 +342,6 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
             showFragment(mCurrentFragmentId);
     }
 
-    /**
-     * Stop audio player and save opened tab
-     */
-    @Override
-    protected void onPause() {
-        super.onPause();
-        mNavigationView.setNavigationItemSelectedListener(null);
-        if (getChangingConfigurations() == 0) {
-            /* Check for an ongoing scan that needs to be resumed during onResume */
-            mScanNeeded = mMediaLibrary.isWorking();
-        }
-        /* Save the tab status in pref */
-        mSettings.edit().putInt("fragment_id", mCurrentFragmentId).apply();
-        if (mExtensionServiceConnection != null) {
-            unbindService(mExtensionServiceConnection);
-            mExtensionServiceConnection = null;
-        }
-        if (currentIdIsExtension())
-            mSettings.edit()
-                    .putString("current_extension_name", mExtensionsManager.getExtensions(getApplication(), false).get(mCurrentFragmentId).componentName().getPackageName())
-                    .apply();
-
-    }
-
     protected void onSaveInstanceState(Bundle outState) {
         if (mCurrentFragment instanceof ExtensionBrowser)
             mCurrentFragment = null;



More information about the Android mailing list