我正在用我的可穿戴应用程序的几页发送一份通知。对于每个datamapItem,都有一个独立的页面,其中包含一个contentAction。content调用一个新的活动,并从datamapitem提交一个"id“。这个"id“应该显示在新的活动中。
ListenerService,它创建通知:
for (int i=dataMapItem.getDataMap().size()-1; i>=0; i--) {
...
Intent detailIntent = new Intent(this, DetailActivity.class);
detailIntent.putExtra(DetailActivity.EXTRA_ID, id);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Action action = new Notification.Action(R.drawable.btn_blue_small, "open", pendingIntent);
actions.add(action);
if(i!=0) {
Notification notificationPage = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(text)
.extend(new Notification.WearableExtender()
.setBackground(colorBitmap)
.setContentAction(i)
)
.build();
pages.add(notificationPage);
} else {
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(text)
.extend(new Notification.WearableExtender()
.addActions(actions)
.addPages(pages)
.setContentAction(i)
.setBackground(colorBitmap)
.setHintHideIcon(true)
);
Notification notification = notificationBuilder.build();
notification.defaults |= Notification.DEFAULT_VIBRATE;
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.notify(NOTIFICATION_ID, notification);
}
}SecondActivity,它应该显示通过intent.putextra()实现的数据
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mTextid = (TextView) findViewById(R.id.txtid);
Intent intent = getIntent();
if(intent != null) {
id = intent.getStringExtra(EXTRA_ID);
...
}所以我的问题是:因为我的putExtra的键是静态的,所以这个值在循环的每一次运行中都会被覆盖。第二次活动中显示的id始终为0,或上次运行时的值。
我希望我描述了这一点,可以理解;)有谁有办法解决这个问题?谢谢
发布于 2014-09-09 14:53:44
我自己解决的。只是个愚蠢的错误。如果有人关心,这只是一个错误的参数,从挂起的意图。
它应该是:
PendingIntent pendingIntent = PendingIntent.getActivity(this, index,
detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);而不是:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);https://stackoverflow.com/questions/25426809
复制相似问题