【发布时间】:2014-11-10 14:31:44
【问题描述】:
在我的第一个活动中,我想将两个字符串数组列表传递给另一个活动,但由于某种原因,当我从第二个活动中提取值时,包丢失了所有值。下面是发送的相关代码:
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Bundle b = new Bundle();
b.putStringArrayList("fName", friendNames);
b.putStringArrayList("fIds", friendIds);
Intent intent = new Intent(getApplicationContext(), Friendrequest.class);
PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT).cancel();
intent.putExtras(b);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// creates notification
Notification n = new Notification.Builder(this)
.setContentTitle("You have a friend request!")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).setAutoCancel(true).build();
notificationManager.notify(0, n);
这里是接收的相关代码:
names = new ArrayList<String>();
ids = new ArrayList<String>();
Bundle b = new Bundle();
b = getIntent().getExtras();
names = b.getStringArrayList("fName");
ids = b.getStringArrayList("fIds");
现在,在我在代码的第一个 sn-p 中创建通知后,我检查以确保“friendNames”数组列表确实包含正确的值,然后我调用 b.containsKey("fName") 并返回 true ,但是一旦我检查代码的第二个 sn-p 中的“名称”数组列表,就没有任何值存在,当我调用 b.containsKey("fName") 时,它返回 false。知道我做错了什么吗?
【问题讨论】: