小编bia*_*ova的帖子

Android:我的部分内容在未决意图中迷失了

我是第一次制作Android应用程序,我遇到了这个问题.当用户A向另一个用户B发送好友请求时,用户B获得通知.我希望当用户B点击通知时重定向到用户A配置文件.

主要活动(应用程序中的主页)根据用户来自何处打开不同的片段.用户简档就是这样一个片段.

这就是我从主活动的演示者类发送通知的方式.

Intent notificationIntent = new Intent(activity.getApplicationContext(), MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

Bundle extras = new Bundle();
extras.putString("name" ,this.friendRequestFromUserName.toString());
extras.putString("email", this.friendRequestFromUserEmail);
extras.putString("notification", "notificationFriendRequest");

notificationIntent.putExtras(extras);

System.out.println("PUTTING EXTRA");
System.out.println(notificationIntent.getExtras().toString());
// output here is:
//Bundle[{name=The Lion King, email=mufasa@lionking.com, notification=notificationFriendRequest}]

NotificationCompat.Builder builder = new NotificationCompat.Builder(activity)
    .setSmallIcon(R.drawable.ic_notification)
    .setContentTitle("New friend!")
    .setContentText(this.friendRequestFromUserName + " wants to be friends.")
    .setAutoCancel(true)
    .setOnlyAlertOnce(true)
    .setOngoing(false)
    .setContentIntent(PendingIntent.getActivity(activity.getApplicationContext(), 0, notificationIntent, 0));

builder.setOngoing(false);
builder.setAutoCancel(true);

Notification not = builder.build();
not.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager manager = (NotificationManager)this.activity.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(123, not);
Run Code Online (Sandbox Code Playgroud)

但是在主要活动中,当用户点击通知时,只有部分Bundle是"到达".以下是我尝试获取额外内容的方法:

    extraName = intent.getStringExtra("name");
    extraMail = intent.getStringExtra("email");
    extra = …
Run Code Online (Sandbox Code Playgroud)

android extras android-intent android-fragments android-pendingintent

5
推荐指数
1
解决办法
1822
查看次数