}
@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
mDelayedStopHandler.removeCallbacksAndMessages(null);
Message msg = mDelayedStopHandler.obtainMessage();
mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
+ return START_STICKY;
}
@Override