2012-12-02 104 views
2

当一个widget图标clicked.What我要的是那件的位置发送到activity.I在我的onUpdate procedure.But试图在主屏幕上获取appwidget位置?

 Intent intent=new Intent(context, WidgetActivity.class); 
     Bundle bundle = new Bundle(); 
     bundle.putString("rect", bound); 
     intent.putExtras(bundle); 

     //intent.putExtra("rect", bound.toString()); 
     PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,intent, 0); 
     RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.pic1); 

     views.setOnClickPendingIntent(R.id.wbutton1, pendingIntent); 

     appWidgetManager.updateAppWidget(appWidgetId, views); 

这个崩溃的活动,我开始一个活动。 我听说这个职位是使用intent.getsourceBounds()返回的。在onReceive ryt中我已经尝试了绑定一个全局变量。从onReceive设置它的值为bound=intent.getsourceBounds();这也行不通。

所以我的问题是 1.如何在onUpdate中使用intent.getsourceBounds()获取小工具的位置? 2.如何将它发送到活动?

谢谢你的时间。

编辑:我设法从控件发送字符串的活动是这样的:

 Intent intent=new Intent(context, WidgetActivity.class); 
     Bundle bundle = new Bundle(); 
     bundle.putString("pos", "hello"); 
     intent.putExtras(bundle); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_CANCEL_CURRENT); 

编辑2:我发现https://stackoverflow.com/a/5324918/1685829它说,它可以用getSourceBounds()来完成谁能解释我如何可以使用它在onUpdate。

回答

1

你不需要发送它; Android为你做。 getSourceBounds()只能从活动内部使用。此信息在onUpdate()内不可用。