我需要在我的应用程序运行时在状态栏中放置通知,但我不希望它在选中后回调我的活动。它只是向用户提供应用程序正在运行的信息 - 基本上是一个提醒,以防他们按下主页按钮并将其最小化。
想法?
答案 0 :(得分:1)
我有同样的期望行为。我的解决方案是:
Intent intent = new Intent(this, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
此外,要在用户选择时自动消失通知
notification.flags |= Notification.FLAG_AUTO_CANCEL;
答案 1 :(得分:1)
Intent intent = new Intent(this,YourActivity.class);
或只是
Intent intent = new Intent();
答案 2 :(得分:0)
我最终提出了解决这个问题的方法,尽管它基本上是一个黑客攻击。而不是将意图设置为指向我正在使用Dialog类的Activity类。
this.notificationIntent = new Intent(this, SomeDialog.class);
现在,如果用户通过logcat选择通知,我可以看到记录了启动活动,但似乎没有任何反应。
这允许我发布在我的应用程序运行时保留的通知,然后我会在用户退出时将其关闭。