【问题标题】:make notification when clicking app bring to front单击应用程序时发出通知带到前面
【发布时间】:2012-02-02 14:49:26
【问题描述】:

我想发出一个通知,点击它会将我的应用程序从后台带到前台。我正在使用以下代码:

NotificationManager noma = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent, 0);
intent.putExtra("key", "trigerred");
String body = "This is a message";
String title = "This is title";
Notification no = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis());
no.defaults = Notification.DEFAULT_ALL;
no.setLatestEventInfo(this, title, body, pen);
noma.notify(uniqueID, no);

当我点击创建新意图的通知但我希望将最后创建的意图带到前面时。我该怎么做?

【问题讨论】:

标签: android


【解决方案1】:

您需要在传递给 getActivity 的意图上设置 FLAG_ACTIVITY_SINGLE_TOP 标志。 当您单击通知时,这应该会让您回到所有准备就绪的正在运行的活动。

有关不同启动标志的列表,请参阅 here

【讨论】:

  • 我这样做了,但它不起作用。可以举个例子吗?
  • 抱歉,重新阅读文档我认为您需要设置 FLAG_ACTIVITY_NEW_TASK 标志。此标志会将 Activity 启动到新任务中,但如果存在已准备好此 Activity 的任务,则它将改为将其带到前台。
【解决方案2】:

试试这个

PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent,Intent.FLAG_ACTIVITY_TASK_ON_HOME);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多