[Android] Properly stop playback & unregister receivers when the service stops.

Sébastien Toque git at videolan.org
Tue Nov 6 22:32:56 CET 2012


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Tue Nov  6 22:26:51 2012 +0100| [c83f08cad64642d15194167de448ad1992a5f7a2] | committer: Sébastien Toque

Properly stop playback & unregister receivers when the service stops.

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

 vlc-android/src/org/videolan/vlc/AudioService.java |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index ba03cbd..38b9305 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -92,6 +92,7 @@ public class AudioService extends Service {
      * RemoteControlClient is for lock screen playback control.
      */
     private RemoteControlClient mRemoteControlClient = null;
+    private RemoteControlClientReceiver mRemoteControlClientReceiver = null;
 
     /**
      * Distinguish between the "fake" (Java-backed) playlist versus the "real"
@@ -148,7 +149,8 @@ public class AudioService extends Service {
             if (stealRemoteControl)
                 filter.setPriority(Integer.MAX_VALUE);
             filter.addAction(Intent.ACTION_MEDIA_BUTTON);
-            registerReceiver(new RemoteControlClientReceiver(), filter);
+            mRemoteControlClientReceiver = new RemoteControlClientReceiver();
+            registerReceiver(mRemoteControlClientReceiver, filter);
         }
 
         AudioUtil.prepareCacheFolder(this);
@@ -212,9 +214,14 @@ public class AudioService extends Service {
     @Override
     public void onDestroy() {
         super.onDestroy();
+        stop();
         if (mWakeLock.isHeld())
             mWakeLock.release();
         unregisterReceiver(serviceReceiver);
+        if (mRemoteControlClientReceiver != null) {
+            unregisterReceiver(mRemoteControlClientReceiver);
+            mRemoteControlClientReceiver = null;
+        }
     }
 
     @Override



More information about the Android mailing list