I just created my first ever widget and it all went well until I got to the part where I'm supposed to set when it updates. Here's my code to make my question clear:
Android Manifest:
<receiver android:name="com.whizzapps.stpsurniki.widget.UrnikWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/app_widget_info"/>
</receiver>
App Widget Provider XML:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="80dp"
android:minHeight="40dp"
android:updatePeriodMillis="10"
android:initialLayout="@layout/app_widget"
android:widgetCategory="home_screen" >
</appwidget-provider>
AppWidgetProvider class:
public class UrnikWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
Log.i("TAG", "onUpdate");
}
}
I have created a simple widget with a TextView in it that displays a certain word, it has no logic at all yet since I'm still learning how to work with widgets. As you can see I made a log.i to see when onUpdate is actually called and my problem is that it is only called the first time I put the widget on my home screen.
I know that update interval of 10 milliseconds is too low and should not be used because of battery drain but I'M USING 10ms just for testing purposes.
Why does onUpdate only executes once instead of every 10ms? And what would be the best way for me to update widget if I need it updated at certain hours only? Let's say I only need my widget to be updated at 7AM, 8AM and 3PM. Is this possible? Thank you!