[Android] Prevent device rescan at every rotation

Geoffrey Métais git at videolan.org
Tue Jul 28 18:23:43 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 28 18:22:49 2015 +0200| [f65ecf2f431ca056b1efc7931bcd22c38303e0fa] | committer: Geoffrey Métais

Prevent device rescan at every rotation

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

 .../videolan/vlc/gui/AudioPlayerContainerActivity.java |   16 ++++++++++++++--
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java |   14 ++++----------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index d964707..887e407 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -69,6 +69,8 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
     private final PlaybackServiceActivity.Helper mHelper = new PlaybackServiceActivity.Helper(this, this);
     protected PlaybackService mService;
 
+    protected boolean mPreventRescan = false;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         /* Get settings */
@@ -120,6 +122,12 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
     }
 
     @Override
+    protected void onRestart() {
+        super.onRestart();
+        mPreventRescan = true;
+    }
+
+    @Override
     protected void onStop() {
         super.onStop();
         unregisterReceiver(storageReceiver);
@@ -137,11 +145,15 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
     }
 
     public void updateLib() {
+        if (mPreventRescan){
+            mPreventRescan = false;
+            return;
+        }
         FragmentManager fm = getSupportFragmentManager();
         Fragment current = fm.findFragmentById(R.id.fragment_placeholder);
-        if (current != null && current instanceof IRefreshable) {
+        if (current != null && current instanceof IRefreshable)
             ((IRefreshable) current).refresh();
-        } else
+        else
             MediaLibrary.getInstance().loadMediaItems();
         Fragment fragment = fm.findFragmentByTag(SidebarAdapter.SidebarEntry.ID_AUDIO);
         if (fragment != null && !fragment.equals(current)) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 6d5ae05..19702bd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -105,7 +105,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
 
     private int mVersionNumber = -1;
     private boolean mFirstRun = false;
-    private boolean mScanNeeded = false;
 
     private Handler mHandler = new MainActivityHandler(this);
     private int mFocusedPrior = 0;
@@ -135,9 +134,11 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
             Util.commitPreferences(editor);
         }
 
-        /* Load media items from database and storage */
         mMediaLibrary = MediaLibrary.getInstance();
-        mMediaLibrary.loadMediaItems();
+        if (savedInstanceState == null) { // means first creation, savedInstanceState is not null after rotation
+        /* Load media items from database and storage */
+            mMediaLibrary.loadMediaItems();
+        }
 
         /*** Start initializing the UI ***/
 
@@ -223,10 +224,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
         if (getIntent() != null && getIntent().hasExtra(PlaybackService.START_FROM_NOTIFICATION))
             getIntent().removeExtra(PlaybackService.START_FROM_NOTIFICATION);
 
-
-        /* Load media items from database and storage */
-        if (mScanNeeded)
-            mMediaLibrary.loadMediaItems();
         if (mSlidingPane.getState() == mSlidingPane.STATE_CLOSED)
             mActionBar.hide();
    }
@@ -273,9 +270,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
     @Override
     protected void onPause() {
         super.onPause();
-
-        /* Check for an ongoing scan that needs to be resumed during onResume */
-        mScanNeeded = mMediaLibrary.isWorking();
         /* Stop scanning for files */
         mMediaLibrary.stop();
         /* Save the tab status in pref */



More information about the Android mailing list