2011-01-11 152 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)));