[Android] Check service connection in dialog cancel

Geoffrey Métais git at videolan.org
Mon May 30 14:31:23 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 30 14:28:10 2016 +0200| [8c9029aa3b2d8720f548155ef8f41fd83efb3841] | committer: Geoffrey Métais

Check service connection in dialog cancel

> https://code.videolan.org/videolan/vlc-android/commit/8c9029aa3b2d8720f548155ef8f41fd83efb3841
---

 vlc-android/src/org/videolan/vlc/PlaybackService.java  |  6 +-----
 vlc-android/src/org/videolan/vlc/media/MediaUtils.java | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index f3c5d19..b97f067 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -2164,11 +2164,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         public void disconnect() {
             if (mBound) {
                 mBound = false;
-                try {
-                    mContext.unbindService(mServiceConnection);
-                } catch (IllegalArgumentException e) {
-                    //Safety catch
-                }
+                mContext.unbindService(mServiceConnection);
             }
         }
 
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
index f294c90..5f71c17 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
@@ -237,7 +237,8 @@ public class MediaUtils {
 
     private static class DialogCallback extends BaseCallBack {
         private final ProgressDialog dialog;
-        final private Runnable mRunnable;
+        private final Runnable mRunnable;
+        private boolean performAction = true;
 
         private interface Runnable {
             void run(PlaybackService service);
@@ -254,7 +255,12 @@ public class MediaUtils {
             dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                 @Override
                 public void onCancel(DialogInterface dialog) {
-                    mClient.disconnect();
+                    synchronized (this) {
+                        if (performAction)
+                            performAction = false;
+                        else
+                            mClient.disconnect();
+                    }
                 }
             });
             mClient.connect();
@@ -262,7 +268,12 @@ public class MediaUtils {
 
         @Override
         public void onConnected(PlaybackService service) {
-            mRunnable.run(service);
+            synchronized (this) {
+                if (performAction) {
+                    performAction = false;
+                    mRunnable.run(service);
+                }
+            }
             dialog.cancel();
         }
 



More information about the Android mailing list