The PreferenceActivity seems like a really easy helper class to manage the preferences of an app.
I'd like to also use that same class from the widget.
On the first instance of a widget I want the PreferenceActivity to come up. This was very easy to do from the configuration activity but here is the glitch...
I can't tell when the preference edit is completed!
All examples of widget preferences I see on the net use a manually built preference screen rather than the PreferenceActivity helper class and then listen for the 'save' button being clicked.
How can I do that with the PreferenceActivity since that activity doesn't have a save button. You just use the 'back' button to commit your preferences changes.
Thanks!
You should be able to tell when the Preference edits are complete by implementing a SharedPreferences.OnShredPreferenceChangeListener. Using this, you could update only when certain keys are changed, or unconditionally when any are changed. Remember to register it in your PreferenceActivity onCreate and unregister it in the onDestroy.
In this case, you can do something similar to Android: How do I force the update of all widgets of a particular kind within the listener to cause all of your widgets to update based on a SharedPreference change.
It's an old question, so this may not be relevant anymore.
I have been trying to do the same thing and I think I've cracked it. I handle the onBackPressed() event in the PreferenceActivity and perform a widget update from there using sendBroadcast().
In PreferenceActivity:
In your WidgetProvider:
NOTE: In 1.5 onBackPressed isn't support so comment out the @Override for onBackPressed and add this code
I should add that I'm new to Android development so I may be doing this entirely wrong. All I can say it is works for me :)
Let me know how you get on.