Подтвердить что ты не робот

Android: Как возобновить приложение из уведомления?

Я пытаюсь запрограммировать свое уведомление, чтобы возобновить свое приложение, вместо того, чтобы просто запускать новый экземпляр моего приложения... Я в основном ищу его, чтобы сделать то же самое, что и при нажатии кнопки "Домой", и приложение возобновлено оттуда.

Вот что я сейчас делаю:

void notifyme(String string){

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager)
                                                getSystemService(ns);

    int icon = R.drawable.notification_icon;        // icon from resources
    CharSequence tickerText = string + " Program Running...";     // ticker-text
    long when = System.currentTimeMillis();         // notification time
    Context context = getApplicationContext();      // application Context
    CharSequence contentTitle = *********;  // expanded message title
    CharSequence contentText = string + " Program Running...";//expanded msg text

    Intent notificationIntent = new Intent(this, Main.class);
    PendingIntent contentIntent = PendingIntent.getActivity(
                                                this, 0, notificationIntent, 0);

    // the next two lines initialize the Notification, using the configurations
    // above
    Notification notification = new Notification(icon, tickerText, when);
    notification.setLatestEventInfo(context, contentTitle, contentText,
                                                                contentIntent);
    final int HELLO_ID = 1;
    mNotificationManager.notify(HELLO_ID, notification);
}

Я предполагаю, что новая линия Intent - вот где проблема... любая помощь будет оценена!

4b9b3361

Ответ 1

вам нужно установить флаги

 notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;   
 notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

Кроме того, если вы никогда не захотите, чтобы дублирующее действие давало ему этот атрибут в манифесте

android:launchMode="singleTask"