[英]Android - Click on notification opens up my main activity, how do I make it open up something else
我有一个简单的应用程序,根据您按下的三个按钮之一显示Android通知。
狗,猫或老鼠
如果您按下狗,则显示“狗”显示的通知。 如果按cat,则显示“Cat”的通知。 如果按鼠标,则显示“鼠标”显示的通知。
当您单击通知时,它会将我带到我的主要活动(再次使用三个按钮)。 我希望它能够将我带到一个单独的活动,该活动将读取所点击的通知,并将通知中的文本设置为textView。
关于如何做到这一点的任何想法?
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());
资料来源: http : //developer.android.com/guide/topics/ui/notifiers/notifications.html#Actions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.