2011-01-11 109 views
0

嘿,我有應用程序小部件,我想通過點擊小部件發送一些數據到附加到PendingIntent的意圖。 這裏是我的代碼應用程序小部件捆綁?

final int N = appWidgetIds.length; 
for (int i = 0; i < N; i++) { 
    int appWidgetId = appWidgetIds[i]; 
    Intent intent = new Intent(context, UpComingBDays.class); 
    if(bdaysAmount != 0){ 
    Bundle bundle = new Bundle(); 
    bundle.putIntegerArrayList("WIDGETIDS", tempAllIDS); 
    intent.putExtras(bundle); 
    System.out.println("bund insertedddddddddddddd....................."); 
    } 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, 
     intent, 0); 
    RemoteViews remoteView = new RemoteViews(context.getPackageName(), 
     R.layout.widget_layout); 
    remoteView.setTextViewText(R.id.widget_text, finalText4TextView); 
    remoteView.setOnClickPendingIntent(R.id.WidgetImageButton, pendingIntent); 
    appWidgetManager.updateAppWidget(appWidgetId, remoteView); 
} 
super.onUpdate(context, appWidgetManager, appWidgetIds); 

我認識總是「外灘insertedddddddddd ......」被印在目錄下載,但目的的包是空。

有什麼不對?我怎樣才能發送數據通過點擊小部件。 plz不要提供使用服務,因爲我的代碼沒有任何東西。 非常感謝。

回答

0

當您創建PendingIntent時,請嘗試使用FLAG_UPDATE_CURRENT

+0

謝謝回答CW。我沒有使用你的建議,因爲我已經改變了解決這個問題的方法。最初我正在做一些計算和服務調用的widget類,但我改變了這一點,把所有的邏輯連接意圖。 – 2011-01-12 01:11:42

0

對不起了半年:)對於那些,誰就會發現這個帖子的時候得到這個問題的回答後後:我已經發現,FLAG_UPDATE_CURRENT是不夠的:

http://developer.android.com/reference/android/app/PendingIntent.html

該標誌不會如果您需要更多的1個小部件與intents捆綁中的不同數據,則會工作,因爲Intent將被覆蓋。

要解決這個問題,你將需要更新的意圖數據:

http://developer.android.com/guide/topics/appwidgets/index.html

// When intents are compared, the extras are ignored, so we need to embed the extras 
// into the data so that the extras will not be ignored. 
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));