从窗口小部件的数据发送到活动 [英] Send data from widget to activity
问题描述
我想从我的窗口小部件的数据发送到我的活动。
我见过有关部件侧的几个话题,但我没有成功让我活动的数据。
I'm trying to send data from my widget to my activity. I've seen several topics about the widget side, but I didn't succeed to get the data in my activity.
请参阅从部件将数据传递到应用
在我的活动我尝试在调用onStart做()方法:
In my Activity I try to do in the onStart() method:
Intent intent = getIntent();
if(intent.getStringExtra("he")!=null)
LogWrapper.debug(MainActivity.class, "DATA "+intent.getStringExtra("he"));
else
LogWrapper.debug(MainActivity.class, "DATA null");
但意图始终为空。
But Intent is always null.
小工具提供方:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
LogWrapper.info(DefibWidgetProvider.class,"in onUpdate!");
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch MainActivity
Intent intent = new Intent(context, MainActivity_.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("he","Hello !");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_defib);
views.setOnClickPendingIntent(R.id.refreshButton, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
上下文:我的应用程序包含了谷歌地图。
我有2个按钮,在我的窗口小部件,而我想开在MainActivity和中心在地图上特殊的长/纬度当用户点击这些按钮中的一个。
Context : My app contains a Google map. I have 2 buttons in my widget, And I want to open the mainactivity and center the map on a special long/lat when the user click one of these buttons.
你能帮我做这个工作?谢谢
Could you help me to make this working ? thank you
推荐答案
根据您的建议的链接,你会得到onNewIntent方法中你的意图的数据,
As per your suggested link, you will get your intent's data inside onNewIntent method,
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
super.onNewIntent(intent);
}
从这个方法里面让你的意图的数据。
Get your intent data from inside this method.
这篇关于从窗口小部件的数据发送到活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!