[Android] Directly start service if context is an activity

Geoffrey Métais git at videolan.org
Tue Mar 13 09:28:31 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 12 16:03:10 2018 +0100| [df65474f434f9cdf93d2a6e50499a3fe1e6167fb] | committer: Geoffrey Métais

Directly start service if context is an activity

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

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 112662197..d9c4107ef 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -21,6 +21,7 @@
 package org.videolan.vlc;
 
 import android.annotation.TargetApi;
+import android.app.Activity;
 import android.app.KeyguardManager;
 import android.app.Notification;
 import android.app.PendingIntent;
@@ -1878,7 +1879,8 @@ public class PlaybackService extends MediaBrowserServiceCompat{
         public void connect() {
             if (mBound) throw new IllegalStateException("already connected");
             final Intent serviceIntent = getServiceIntent(mContext);
-            Util.startService(mContext, serviceIntent);
+            if (mContext instanceof Activity) mContext.startService(serviceIntent);
+            else Util.startService(mContext, serviceIntent);
             mBound = mContext.bindService(serviceIntent, mServiceConnection, BIND_AUTO_CREATE);
         }
 



More information about the Android mailing list