如何向小部件传递参数?
我正在开发一个小部件,我在这里有一个基本问题。
当用户单击小部件时。它将进入配置页面。我这里使用PendingIntent。
Intent intent = new Intent(this, MyConfig.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
views.setOnClickPendingIntent(R.id.MyWidget, pendingIntent);
然后在配置页面上,我在这里有一些业务逻辑,我想将结果(对象)传递回更新小部件。
我使用下面的代码强制更新小部件,
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(MyConfig.this);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(MyConfig.this, MyActivity.class));
if (appWidgetIds.length > 0) {
new MyActivity().onUpdate(MyConfig.this, appWidgetManager, appWidgetIds)
};
如何执行此操作? 我应该将 Object 参数放在哪里,以便可以在 MyActivity 类上访问它?
谢谢
I'm developing a widget and I have basic question here.
When user click on the widget. It will go to config page. I use PendingIntent here.
Intent intent = new Intent(this, MyConfig.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
views.setOnClickPendingIntent(R.id.MyWidget, pendingIntent);
On the config page then, I have some business logic here and I want to pass the result which is Object back to update widget.
I use codes below to force an update to widget
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(MyConfig.this);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(MyConfig.this, MyActivity.class));
if (appWidgetIds.length > 0) {
new MyActivity().onUpdate(MyConfig.this, appWidgetManager, appWidgetIds)
};
How is the appropriate technique to do it?
Where I should put the Object parameter so I can access it on MyActivity class?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不使用共享首选项?
Why not using sharedPreferences?