Possible to make an Android Notification that does not call an Intent? [closed]

最后都变了- 提交于 2019-12-02 10:56:09

I have the same desired behavior. My solution was:

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);

Also, to make the notification automatically disappear when selected by the user

notification.flags |= Notification.FLAG_AUTO_CANCEL;

Intent intent = new Intent(this, YourActivity.class);

or just

Intent intent = new Intent();

I ended up coming up with a solution to this issue although its basically a hack. instead of setting the intent to point to an Activity class I'm using a Dialog class.

this.notificationIntent = new Intent(this, SomeDialog.class);

Now if the user selects the notification, via the logcat, I can see the Starting Activity logged, but it appears nothing happens.

This allows me to post a notification that stays while my app is running and then I just dismiss it when the user exits.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!