我想使用Messenger作为我的appwidget和活动之间的IPC机制。信使消失从捆绑onCreate
我执行以下操作: 我创建了一个意图,当我的appwidget上的按钮被单击时,开始一个特定的活动。
intent = new Intent(mContext, TorchLightActivity.class);
intent.putExtra(RPC, new Messenger(mHandler));
intent.putExtra(TYPE, mType);
...
final PendingIntent actionPendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
remoteView.setOnClickPendingIntent(layout, actionPendingIntent);
当我点击我的微件按钮活动启动
onCreate(...)
final Bundle bun = getIntent().getExtras();
// Get null here
mMessanger = (Messenger) bun.get(FlashlightModule.RPC);
// Working great
mType = bun.getInt(FlashlightModule.Type);
当在捆绑的样子,我可以看到的唯一额外的数据我已经是FlashlightModule.Type
例如int值。
这样做的目的是从一开始就创建额外(见Get the intent from onCreate in Android),并使用setData从一开始就使用(见Application widget with bundle?)
是否有可能在所有AppWidget之间的信使传递给我自己的活动?
谢谢。
我发现了一个奇怪的行为,也许有人可以阐明它。我正在使用setData来区分它与类似的意图(我使用相同的活动,但具有不同的额外)。突然删除setData时,包裹正确传递。 – 2011-12-23 22:08:04