2

I developed an app with:

  • a button to insert some data in a sqlite db
  • some views to show and update the sqlite db records

Now i'd like to write a simple widget that just perform the app button action: insert some data in the SAME sqlite db. The goal is to use the widget for fast insert without opening the app, and the app when i need more complex opertions.

  1. is the widget the right way to do it?
  2. is it possible to share the same db between the app (the real owner) and the widget? how?
  3. do I need a contentProvider?

Thanks

1 Answer 1

3

is it possible to share the same db between the app (the real owner) and the widget?

Yes.

how?

Usually, the app widget is just part of the app. You use it no differently than you would from an activity or fragment, or anything else, since it is all one app.

Do bear in mind, though, that AppWidgetProvider methods like onUpdate() are called on the main application thread. In an activity, you might just use a bare thread to do database I/O, which is OK, as your app is in the foreground. For an app widget update, though, your app may be in the background, and your process may not live very long. Use an IntentService to do the database I/O (kicked off by onUpdate()) and update the app widget contents.

do I need a contentProvider?

Only if you want your app widget to be in a separate app from the rest of your app code. Usually, that is not a good idea, as then users have to install two apps (the main app plus the app widget app).

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

4 Comments

because I'm very new to android development, I ask you some more details...how can i develop a widget that is part of my app? the best would be if for the button in the widget i can set the call back method the is in the main app
OK, I'm reading the guide. Just one more question... If I develop an app widget with a button to interact with the main app, does it mean the main app is loaded and working in backgroud? all the time? In this case I think it's better a widget that share the db and don't need a background working app. Is it right?
@acca2o: "all the time?" -- no. Only when the app widget needs to be updated, or if the user clicks on something in the app widget, will your process need to be running to support the app widget.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.