3

I am making a app which allow users to create and delete spaces. Example of spaces: office, meeting room, shop, etc. A user will set a space when he is in that location. Example if he is at office he will set the space to office.

The spaces are stored in a database. I have a home screen widget, and this widget needs to show the space that is set. Example needs to show office now.

I had some difficulty getting the widget to show these spaces. The problem is that the widget only updates after 30 min and when you do change it to update every second than you are faced with battery issues.

I only want the widget to update when a space is set.

Does anyone know how to deal with this problem or has some good advice. Or know of any good tutorials which actually work this way.

I am new to android and java.

Triad sou.
  • 2,969
  • 3
  • 23
  • 27
Ann
  • 51
  • 1
  • 4

3 Answers3

2

you can use this library: Android SQLiteAssetHelper

An Android helper class to manage database creation and version management using an application's raw asset files.

It helped me :)

j0k
  • 22,600
  • 28
  • 79
  • 90
S.Hossein Asadollahi
  • 1,450
  • 2
  • 17
  • 22
2

Yes, the link given by dave.c is largely correct, but if one is using a widget backed by a collection, a database in my case, a slight modification gives the intended result:

private void updateAllWidgets() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext().getApplicationContext());
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(getContext().getApplicationContext(), ListWidgetProvider.class));
    if (appWidgetIds.length > 0) {
        // Tell the widgets that the list items should be invalidated and refreshed!
        // Will call onDatasetChanged in ListWidgetService, doing a new requery
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.notes_list);
    }
}
Jonas Kalderstam
  • 1,136
  • 12
  • 27
1

If you want to update a widget programatically, you can use the approach in this answer

Community
  • 1
  • 1
dave.c
  • 10,910
  • 5
  • 39
  • 62