Код: Выделить всё
long when = System.currentTimeMillis();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(R.string.app_name);
Notification notification = new Notification(R.drawable.app_notification_icon, "De Centrale", when);//message
Intent notificationIntent = new Intent(context, B.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, title, msg, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
Код: Выделить всё
intent = new Intent(this, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
Но если я нажму кнопку Нажимаю кнопку «Домой», а затем запускаю приложение из «Недавнего приложения», после чего появляется старый экран B с «B-notification-intent». Вместо этого мне нужно последнее намерение, то есть «B-A-намерение». Я использую этот код в B:
Код: Выделить всё
@Override
protected void onCreate(Bundle b)
{
fetchDataFromDB(getIntent());
}
@Override
protected void onNewIntent(Intent intent)
{
fetchDataFromDB(intent);
}
Подробнее здесь: https://stackoverflow.com/questions/131 ... ecent-task