[Android] fix thumbnail thread leak

Sébastien Toque git at videolan.org
Mon Jul 2 21:02:04 CEST 2012


android | branch: master | Sébastien Toque <xilasz at gmail.com> | Mon Jul  2 20:24:59 2012 +0200| [dd3d61f2db76d30e51598168c97597abcb821434] | committer: Sébastien Toque

fix thumbnail thread leak

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

 vlc-android/src/org/videolan/vlc/ThumbnailerManager.java          |    4 ++++
 vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java |    4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
index e8d4d75..bf3f28e 100644
--- a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
+++ b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
@@ -131,6 +131,10 @@ public class ThumbnailerManager extends Thread {
             //Log.i(TAG, "create new bitmap for: " + item.getName());
             byte[] b = mLibVlc.getThumbnail(item.getLocation(), width, height);
 
+            // Activity stopped & destroyed, abort everything
+            if (isInterrupted())
+                break;
+
             if (b == null) {// We were not able to create a thumbnail for this item.
                 item.setPicture(mVideoListActivity.getActivity(), null);
                 continue;
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 683b554..38c9fa9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
@@ -116,6 +116,8 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
     public void onDestroy() {
         mMediaLibrary.removeUpdateHandler(mHandler);
         mThumbnailerManager.clearJobs();
+        mThumbnailerManager.interrupt();
+        mBarrier.reset();
         mVideoAdapter.clear();
         super.onDestroy();
     }
@@ -208,9 +210,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
                 try {
                     mBarrier.await();
                 } catch (InterruptedException e) {
-                    e.printStackTrace();
                 } catch (BrokenBarrierException e) {
-                    e.printStackTrace();
                 }
                 break;
             case MediaLibrary.MEDIA_ITEMS_UPDATED:



More information about the Android mailing list