[Android] fix IllegalStateException in updateList(s)

Sébastien Toque git at videolan.org
Mon Jul 2 22:16:20 CEST 2012


android | branch: master | Sébastien Toque <xilasz at gmail.com> | Mon Jul  2 22:12:31 2012 +0200| [671c20aff555f6f7cfdb06a27d949147a93118fd] | committer: Sébastien Toque

fix IllegalStateException in updateList(s)

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=671c20aff555f6f7cfdb06a27d949147a93118fd
---

 .../org/videolan/vlc/gui/audio/AudioBrowserFragment.java |   14 ++++++++++++--
 .../org/videolan/vlc/gui/audio/AudioListFragment.java    |   14 ++++++++++++--
 .../org/videolan/vlc/gui/video/VideoListFragment.java    |    7 +++----
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index dc5ce01..3575a84 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -98,7 +98,6 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
         mAudioController = AudioServiceController.getInstance();
 
         mMediaLibrary = MediaLibrary.getInstance(getActivity());
-        mMediaLibrary.addUpdateHandler(mHandler);
 
         mSongsAdapter = new AudioListAdapter(getActivity());
         mArtistsAdapter = new AudioPlaylistAdapter(getActivity(), R.plurals.albums, R.plurals.songs);
@@ -156,6 +155,18 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
         updateLists();
     }
 
+    @Override
+    public void onPause() {
+        super.onPause();
+        mMediaLibrary.removeUpdateHandler(mHandler);
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        mMediaLibrary.addUpdateHandler(mHandler);
+    }
+
     OnItemClickListener songListener = new OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {
@@ -327,7 +338,6 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
 
     @Override
     public void onDestroy() {
-        mMediaLibrary.removeUpdateHandler(mHandler);
         mSongsAdapter.clear();
         mArtistsAdapter.clear();
         mAlbumsAdapter.clear();
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListFragment.java
index 7a39ba6..12e6b2e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListFragment.java
@@ -76,7 +76,6 @@ public class AudioListFragment extends SherlockListFragment {
         mAudioController = AudioServiceController.getInstance();
 
         mMediaLibrary = MediaLibrary.getInstance(getActivity());
-        mMediaLibrary.addUpdateHandler(mHandler);
 
         mSongsAdapter = new AudioListAdapter(getActivity());
         setListAdapter(mSongsAdapter);
@@ -96,8 +95,19 @@ public class AudioListFragment extends SherlockListFragment {
     }
 
     @Override
-    public void onDestroy() {
+    public void onPause() {
+        super.onPause();
         mMediaLibrary.removeUpdateHandler(mHandler);
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        mMediaLibrary.addUpdateHandler(mHandler);
+    }
+
+    @Override
+    public void onDestroy() {
         mSongsAdapter.clear();
         super.onDestroy();
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
index 38c9fa9..ba78f7e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
@@ -76,7 +76,6 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
         mVideoAdapter = new VideoListAdapter(getActivity());
 
         mMediaLibrary = MediaLibrary.getInstance(getActivity());
-        mMediaLibrary.addUpdateHandler(mHandler);
         mThumbnailerManager = new ThumbnailerManager(this);
 
         setListAdapter(mVideoAdapter);
@@ -96,9 +95,9 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
     }
 
     @Override
-    public void onPause()
-    {
+    public void onPause() {
         super.onPause();
+        mMediaLibrary.removeUpdateHandler(mHandler);
     }
 
     @Override
@@ -109,12 +108,12 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
         long lastTime = preferences.getLong("LastTime", 0);
         mVideoAdapter.setLastMedia(lastTime, lastPath);
         mVideoAdapter.notifyDataSetChanged();
+        mMediaLibrary.addUpdateHandler(mHandler);
         super.onResume();
     }
 
     @Override
     public void onDestroy() {
-        mMediaLibrary.removeUpdateHandler(mHandler);
         mThumbnailerManager.clearJobs();
         mThumbnailerManager.interrupt();
         mBarrier.reset();



More information about the Android mailing list