OSDN Git Service

onStart() can now receive a null Intent, so deal with that.
authorMarco Nelissen <marcone@google.com>
Thu, 24 Sep 2009 20:21:06 +0000 (13:21 -0700)
committerMarco Nelissen <marcone@google.com>
Thu, 24 Sep 2009 20:23:13 +0000 (13:23 -0700)
src/com/android/music/MediaPlaybackService.java

index ddca25b..f92bc6d 100644 (file)
@@ -561,28 +561,30 @@ public class MediaPlaybackService extends Service {
     }
 
     @Override
-    public void onStart(Intent intent, int startId) {
+    public int onStartCommand(Intent intent, int flags, int startId) {
         mServiceStartId = startId;
         mDelayedStopHandler.removeCallbacksAndMessages(null);
-        
-        String action = intent.getAction();
-        String cmd = intent.getStringExtra("command");
-        
-        if (CMDNEXT.equals(cmd) || NEXT_ACTION.equals(action)) {
-            next(true);
-        } else if (CMDPREVIOUS.equals(cmd) || PREVIOUS_ACTION.equals(action)) {
-            prev();
-        } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) {
-            if (isPlaying()) {
+
+        if (intent != null) {
+            String action = intent.getAction();
+            String cmd = intent.getStringExtra("command");
+
+            if (CMDNEXT.equals(cmd) || NEXT_ACTION.equals(action)) {
+                next(true);
+            } else if (CMDPREVIOUS.equals(cmd) || PREVIOUS_ACTION.equals(action)) {
+                prev();
+            } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) {
+                if (isPlaying()) {
+                    pause();
+                } else {
+                    play();
+                }
+            } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) {
                 pause();
-            } else {
-                play();
+            } else if (CMDSTOP.equals(cmd)) {
+                pause();
+                seek(0);
             }
-        } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) {
-            pause();
-        } else if (CMDSTOP.equals(cmd)) {
-            pause();
-            seek(0);
         }
         
         // make sure the service will shut down on its own if it was
@@ -590,6 +592,7 @@ public class MediaPlaybackService extends Service {
         mDelayedStopHandler.removeCallbacksAndMessages(null);
         Message msg = mDelayedStopHandler.obtainMessage();
         mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
+        return START_STICKY;
     }
     
     @Override