开发者

Android widgets and handling clicks from multiple instances

For example: I write my own clock widget that can have copies of the clock widget installed. 2 different clocks with 2 different time zones.

When the user touches a specific clock, I'd like to load开发者_JAVA百科 a settings page (app) for that specific clock. So passing some sort of widget ID to the app (settings page).

Is this possible or do I need to load up the settings page(app) and show all "clocks" within my app part.

If it is possible, how do I do this?


It is possible. What you have to do is remember which widget (via appWidgetId) displays which clock (e.g. store it in the SharedPreferences or in a sqlite db). When updating the widgets in your providers onUpdate(), you set a pending intent that launches your configuration activity. Also add an extra to the intent that tells the configuration activity which clocks settings it should display, depending on the appWidgetId that you are currently processing. When starting the activity, use getExtras() to read the extra and display the correct settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜