我想使用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