首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安卓穿戴Intent.putExtra几个页面与contentAction

安卓穿戴Intent.putExtra几个页面与contentAction
EN

Stack Overflow用户
提问于 2014-08-21 12:50:17
回答 1查看 140关注 0票数 0

我正在用我的可穿戴应用程序的几页发送一份通知。对于每个datamapItem,都有一个独立的页面,其中包含一个contentAction。content调用一个新的活动,并从datamapitem提交一个"id“。这个"id“应该显示在新的活动中。

ListenerService,它创建通知:

代码语言:javascript
运行
复制
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()实现的数据

代码语言:javascript
运行
复制
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,或上次运行时的值。

我希望我描述了这一点,可以理解;)有谁有办法解决这个问题?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-09 14:53:44

我自己解决的。只是个愚蠢的错误。如果有人关心,这只是一个错误的参数,从挂起的意图。

它应该是:

代码语言:javascript
运行
复制
PendingIntent pendingIntent = PendingIntent.getActivity(this, index,
                detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);

而不是:

代码语言:javascript
运行
复制
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                    detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25426809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档