user387184
user387184

Reputation: 11053

database error when widget updates

I have a DB in my app which normally works perfectly.
Now, I have added a widget with an update function which also accesses the DB.
Once in a while, I get this error but only from within the widget update method.

Caused by:java.lang.NullPointerException
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)

Is there some kind of restriction on accessing a DB from within widget update method?

Upvotes: 0

Views: 81

Answers (1)

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52936

You shouldn't do any disk IO from the widget's BroadCast receiver (onUpdate()). Start a service that fetches the data and does the actual update. You might want to use an IntentServcie since it starts a worker thread by default.

Upvotes: 1

Related Questions