19.4. 通过 isNotification 判断是否需要执行 onStop() 和 onDestroy()
private boolean isNotification = false;
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent != null) {
boolean isExit = intent.getBooleanExtra("QUIT", false);
if (isExit) {
this.finish();
}
isNotification = intent.getBooleanExtra("Notification", false);
}
Log.d(TAG, "onNewIntent()");
}
@Override
public void onStop() {
super.onStop();
if (isNotification) return;
if (messageQueueService != null) {
stopService(messageQueueService);
}
aigcSpeech.stopSpeech();
Log.d(TAG, "onStop()");
}
@Override
protected void onDestroy() {
super.onDestroy();
if (isNotification) return;
if (messageQueueService != null) {
stopService(messageQueueService);
}
if (mainBroadcastReceiver != null) {
unregisterReceiver(mainBroadcastReceiver);
}
aigcSpeech.stopSpeech();
Log.d(TAG, "onDestroy()");
}