我有一个音频流应用程序在前台的后台and also a foreground service which should control media player from the background. There is a
CLOSE`按钮中播放,预计会在点击时完全杀死该应用。
但是,我用来完成的方法尚未按预期工作。
public void showNotification() {
Intent playPauseIntent = new Intent(this, AudioService.class);
playPauseIntent.setAction(Constants.ACTION_STREAM_PLAY_PAUSE);
PendingIntent playPausePendingIntent = PendingIntent.getService(
this, 0, playPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT
);
Intent deleteIntent = new Intent(this, AudioService.class);
deleteIntent.setAction(Constants.ACTION_STOP_RADIO_SERVICE);
PendingIntent pendingDelete = PendingIntent.getService(this,
0,
deleteIntent,
PendingIntent.FLAG_ONE_SHOT
);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null && intent.getAction() != null) {
switch (intent.getAction()) {
case Constants.ACTION_STOP_RADIO_SERVICE:
hideNotification();
stopSelf();
android.os.Process.killProcess(android.os.Process.myPid());
this.onDestroy();
// not working as expected. i want app killed from here
break;
}
}