相关疑难解决方法(0)

如何从Android上获取额外的数据?

如何将数据从一个活动(意图)发送到另一个活动?

我用这段代码发送数据:

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)

android android-intent

719
推荐指数
10
解决办法
83万
查看次数

确定通知是否调用了Activity

我正在使用带有各种TabsActivitiy.从应用程序的不同部分创建通知,以告知用户某些内容已更改.当用户点击通知时,我现在设法调用活动.但是,如何在运行时或通过单击通知确定活动是以"正常"方式创建的?

(根据单击的通知,我想转发到另一个选项卡而不是显示主选项卡.)

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)

notifications android android-pendingintent

7
推荐指数
1
解决办法
4860
查看次数