如何根据通知打开特定活动 [英] How to open a specific activity based on Notification
问题描述
我目前工作的一个提醒的应用程序中,用户得到的通知与提醒的名称,然后重定向到包含详细提醒的内容的活动。
我然而,只能够每次重定向到相同的活性。
我用这code:
I am currently working on a reminders app in which the user gets a notification with the name of the reminder and is then redirected to an activity which contains the text of the reminder in detail. I am however, only able to redirect to the same activity each time. I am using this code :
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
notification.setLatestEventInfo(this, title, text, contentIntent);
所以这个重定向到在MainActivity上单击通知。我想重定向到一个单独的屏幕,然后根据显示在该活动的文本上的密钥值。
我如何做到这一点?
So this redirects to the MainActivity on clicking the notification. I would like to redirect to a separate screen and then based on a key value display a text on that activity. How do I achieve this ?
感谢
推荐答案
只要改变的PendingIntent
使用其他活动
和/或追加增加了额外的信息意图
您使用创建的PendingIntent
:
Just change the PendingIntent
using another Activity
and/or append extra information on the Intent
you are using to create the PendingIntent
:
Intent launchIntent = new Intent(this, AnotherActivity.class)
launchIntent.putExtra("myKey", "myValue");
//....
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launchIntent , 0);
notification.setLatestEventInfo(this, title, text, contentIntent);
和比,你活动
的的onCreate()
:
//...
getIntent().getStringExtra("myKey")
//do your stuff..
这篇关于如何根据通知打开特定活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!