简体   繁体   中英

How to pass parameter to widget?

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

为什么不使用sharedPreferences?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM