Я создаю уведомление, и когда оно будет получено, приложение будет запущено. Мой вопрос: как я могу прекратить это?Объявление Android продолжает запускать приложение
final private static void generateNotification(Context context, String message){
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(context.getString(R.string.app_name))
.setContentIntent(intent)
.setContentText(message)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
Уведомление называется в GCMIntentService:
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
String response = intent.getExtras().getString("response");
switch(response){
case "logout":
String message = "You logged into another device!";
//displayMessage(context, message);
// notifies user
generateNotification(context, message);
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
break;
default:
break;
}
}
«Когда приложение будет запущено», вы уверены? не при нажатии? – weston
Да, даже если я не нахожу уведомление о запуске приложения – jampez77
Сообщение, откуда вызывается этот код, так как я не думаю, что проблема здесь. – weston