簡體   English   中英

Android:如何從通知中恢復應用程序?

[英]Android: How to resume an App from a Notification?

我正在嘗試將我的通知編程為RESUME我的應用程序,而不是簡單地啟動我的應用程序的新實例...我基本上是在尋找它做同樣的事情,因為長按主頁按鈕並恢復應用程序從那里。

這是我目前正在做的事情:

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系列是問題所在......任何幫助都將不勝感激!

你需要設置你的旗幟

 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"

選定的答案對我來說不起作用,但如果其他人如果查看這個,這確實對我有用從通知中恢復應用程序和堆棧

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM