[Android] respect fragment's lifecycle

Sébastien Toque git at videolan.org
Sun Sep 30 21:36:30 CEST 2012


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sun Sep 30 21:36:09 2012 +0200| [01de694156f1abc4418ac943d9165a58edc75364] | committer: Sébastien Toque

respect fragment's lifecycle

this should fix this error :
java.lang.RuntimeException: Unable to destroy activity
...
Caused by: java.lang.IllegalArgumentException: Receiver not registered:

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

 .../src/org/videolan/vlc/gui/video/VideoListFragment.java    |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

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 99f8289..daa75de 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
@@ -111,7 +111,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
         registerForContextMenu(getListView());
-        
+
         // init the information for the scan (2/2)
         IntentFilter filter = new IntentFilter();
         filter.addAction(ACTION_SCAN_START);
@@ -120,7 +120,6 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
         Log.i(TAG,"mMediaLibrary.ismLoadingThreadrunning() " + Boolean.toString(mMediaLibrary.ismLoadingThreadrunning()));
         if (mMediaLibrary.ismLoadingThreadrunning()) {
             actionScanStart(getActivity().getApplicationContext());
-            
         }
 
         updateList();
@@ -150,10 +149,15 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
     }
 
     @Override
+    public void onDestroyView() {
+        getActivity().unregisterReceiver(messageReceiverVideoListFragment);
+        super.onDestroyView();
+    }
+
+    @Override
     public void onDestroy() {
         mBarrier.reset();
         mVideoAdapter.clear();
-        getActivity().unregisterReceiver(messageReceiverVideoListFragment);
         super.onDestroy();
     }
 



More information about the Android mailing list