1

How to access the sqlite databases inside the widget class. The widget class which extends the appwidgetprovider does not have an activity hence i am not able to access the databases inside it.

1 Answer 1

2

There are 2 approaches for such a problem :

1) you say you don't have an activity inside a widget provider but actually the appwidget will execute inside the application context of your app declaring the widget. When you override

onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)

you receive a context that could be used to get access to a database.

2) however, it would be more androidy to declare a service that would perform the query to the database, manage exceptions, retries, and so on and would provide its data either through a call back to an intent to update your widget, or, better, through a content provider that your widget could address.

Regards, Stéphane

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.