簡體   English   中英

如何不從通知開始活動

[英]How not to start an activity from a notification

使用以下代碼,我希望通知在單擊時消失。 不要開始任何活動。 我怎么做?

NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.icon, "hello", System.currentTimeMillis());
n.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(ctx, NotifyActivity.class);
PendingIntent i = PendingIntent.getActivity(ctx, 0, intent, 0);
n.setLatestEventInfo(ctx, "title", "content", i);
nm.notify(1, n);

我知道我過去采用的一種方法是根本不填寫有關用於創建 PendingIntent 的 Intentu 的任何信息。 在您的示例中,您只需刪除傳遞給“意圖”構造函數的 arguments 即可。

我不完全確定您是否可以將 null 傳遞給 setLatestEventInfo 以獲得待處理的意圖,但如果您不能,我提出的解決方案應該可以工作。

暫無
暫無

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

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