RED_
RED_

Reputation: 3007

Using PreferenceActivity to configure a widget?

This may be a bit of a noob question I'm not sure, sorry if it is but I've done a lot of searching to no avail.

At this current moment in time I have a widget that when added to the homescreen opens a android:configure activity. All well and good, that's how the dev.android site shows it.

I recently stumlbed across the PreferenceActivity though and it seems perfect to what I need. I have a preferences.xml which is straight forward but I'm stuck on the java behind that. How do I implement this exactly? Should I disregard android:configure entirely and get rid of it? Am I supposed to implement the PreferenceActivity side by side with the configure activity?

I have looked at plenty of PreferenceActivity tutorials but of course none of them centre around working with widgets so I'm lost. I want it to work in the same way a Configure activity would work. When you add the widget to the homescreen it pops up so the user can changes things before placing it.

I would really appreciate any help on this. Thanks in advance.

Upvotes: 0

Views: 427

Answers (1)

harshit
harshit

Reputation: 3856

i was looking out for the same thing when I came across your question. I found out further and here are my findings: Though you can set a preferenceActivity as a configuratoin activity for your widget it is not suggested to do so. the reason behind this is that when user sets up multiple widget the value for each instance of your widget update is taken from sharedPreferences(which is, in general, place to store your preferences for the application, also used for saving preferences for your widget). Now since the shared preference saves all preferences same for each instance, all instances of your widget will behave and look same. Unless you want them, it is recommended that you make an activity and save your preferences in sharedPreferences with widgetId concatenated by the preference, this way you can get preference for differenct instances and function accordingly.

If you have anything else to say or any advice, please share as I am going to implement this.

Upvotes: 1

Related Questions