Question

Description of app: Widget displaying some information set to update every 60,000ms. One view Activity that serves as a place to set preferences used by Widget. All preferences save, and update just fine. When the user presses the Close button, the information is updated, and the Widget gets the call to update. The SavedPreferences are called inside the Widget void for onUpdate.

This all works fine. Thank you to many questions already answered here that got me that far!

Here is the issue... When the automatic update fires later, the vars from the SavedPreferences fail to load. Sometimes they do. Sometimes the don't. Since this is running on my tablet, I have no error log to report. What I see is that the Widget doesn't crash, but it displays it's raw XML with none of the TextViews populated with SavedPreferences. What I find really strange is that the even defaults are not loading. That is, the key it's loading is set that if nothing is found, it's supposed to return the default. This normally would be used for, say, the first time the Widget loads, and there are no preferences to load. Why wouldn't the defaults load if the reading of the preferences fails? Why would the reading of the preferences fail so complelety, but only some of the time?

Was it helpful?

Solution

Yep. I'm answering my own question. I think this will be helpful to anyone designing a widget that has preferences set.

The problem is not what I thought. The lack of update occurs when the screen is rotated. Apparently, that triggers refresh to the Widget, but it does not call the onUpdate void. So what you get is the raw XML painting out with no update. And it will stay like that until the next automatic update fires.

So the solution to this problem is to identify how to detect a change in screen orientation, and trigger the onUpdate the same as when my "settings" view closes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top