[英]Android - Click on notification opens up my main activity, how do I make it open up something else
I have a simple app that shows android notifications depending to one of three buttons you press. 我有一个简单的应用程序,根据您按下的三个按钮之一显示Android通知。
Dog, Cat, or Mouse 狗,猫或老鼠
If you press dog then a notification that says "Dog" shows. 如果您按下狗,则显示“狗”显示的通知。 If you press cat then a notification that says "Cat" shows.
如果按cat,则显示“Cat”的通知。 If you press mouse then a notification that says "Mouse" shows.
如果按鼠标,则显示“鼠标”显示的通知。
When you click the notification it just takes me to my main activity (with the three buttons again). 当您单击通知时,它会将我带到我的主要活动(再次使用三个按钮)。 I would like it to take me to a separate activity, that will read what notification was clicked, and set it the text from the notification as a textView.
我希望它能够将我带到一个单独的活动,该活动将读取所点击的通知,并将通知中的文本设置为textView。
Any ideas on how to do this? 关于如何做到这一点的任何想法?
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
Source: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Actions 资料来源: http : //developer.android.com/guide/topics/ui/notifiers/notifications.html#Actions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.