[Android] Directly start service if context is an activity

Geoffrey Métais git at videolan.org
Fri Mar 30 16:51:11 CEST 2018


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

Directly start service if context is an activity

(cherry picked from commit df65474f434f9cdf93d2a6e50499a3fe1e6167fb)

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

 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