如何将数据从一个活动(意图)发送到另一个活动?
我用这段代码发送数据:
Intent i=new Intent(context,SendMessage.class);
i.putExtra("id", user.getUserAccountId()+"");
i.putExtra("name", user.getUserFullName());
context.startActivity(i);
Run Code Online (Sandbox Code Playgroud) 我正在使用带有各种Tabs的Activitiy.从应用程序的不同部分创建通知,以告知用户某些内容已更改.当用户点击通知时,我现在设法调用活动.但是,如何在运行时或通过单击通知确定活动是以"正常"方式创建的?
(根据单击的通知,我想转发到另一个选项卡而不是显示主选项卡.)
Intent intent = new Intent(ctx, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent, 0);
// TODO: Replace with .Build() for api >= 16
Notification noti = new Notification.Builder(ctx)
.setContentTitle("Notification"
.setContentText(this.getName())
.setSmallIcon(R.drawable.icon)
.setContentIntent(pendingIntent)
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS)
.setAutoCancel(true)
.getNotification();
NotificationManager notificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
// Hide the notification after its selected
notificationManager.notify(this.getId(), noti);
Run Code Online (Sandbox Code Playgroud)
这成功调用了我的MainActivity.但是,当Activity被触发时,是否有一些方法被调用pendingIntent?
想在主要活动中定义这样的东西:
onTriggeredByNotification(Notification noti){
//determinte tab, depending on Notification.
}
Run Code Online (Sandbox Code Playgroud)