Android AppWidget RemoteViewsFactory intent和putSerializable / putParcelable

时间:2014-10-01 13:28:40

标签: android android-intent android-appwidget remoteview

在我的小部件中,我有集合中意图所需的设置 方法AppWidgetProvider上的onUpdate子类中的(setPendingIntentTemplate)

以及我的RemoteViewsFactory getViewAt方法:

 Bundle extras = new Bundle();
 extras.putInt("pos", position);
 extras.putInt("date", new DateTime().millisOfDay().get());

 //comment this to work
 extras.putSerializable("d", new DateTime());

 Intent fillInIntent = new Intent();
 fillInIntent.putExtras(extras);

 // Make it possible to distinguish the individual on-click
 // action of a given item
 row.setOnClickFillInIntent(R.id.list_view_row, fillInIntent);

我面临的问题是我的活动已经开始但是没有来自getViewAt方法的额外内容,但是只要我评论extras.putSerializable("d", new DateTime());语句 该活动获得所有其他额外内容,例外情况与Parcelable额外内容相同, 是否记录在AppWidgets setOnClickFillInIntent不支持ParcelableSerializable个附加内容的任何地方?

编辑: 我使用以下意图模板:

 Intent startActivityIntent = new Intent(context, MainActivity.class);
    //startActivityIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |   Intent.FLAG_ACTIVITY_CLEAR_TOP);

    startActivityIntent
            .setAction(Intent.ACTION_VIEW)
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
            .setData(Uri.parse(startActivityIntent.toUri(Intent.URI_INTENT_SCHEME)));


    PendingIntent startActivityPendingIntent = PendingIntent
            .getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    views.setPendingIntentTemplate(R.id.list, startActivityPendingIntent);

1 个答案:

答案 0 :(得分:0)

检查您在AppWidgetProvider中的PendingIntent中传递的是哪种标志 Trouble sending Bundle with PendingIntent to a Broadcast Receiver, data lost