1
votes

I have a simple android widget with a single text view. I extend AppWidgetProvider class, widget information xml - appwidget-provider..., also updated my manifest file as per document provided on android website. I also set android:updatePeriodMillis to 1800020 (~30 minutes).

When I place widget on screen all the code under onUpdate method fires for the first time. But after 1800020 milliseconds, the onUpdate doesn't called again. My widget does not update afterwards. Am I missing something with it?

I extend AppWidgetProvider as follow,

public class Testwidget extends AppWidgetProvider {
int COUNT = 0;

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {

    Log.d("WIDGET", "====================== UPDATED ======================");
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for(int _i=0; _i<appWidgetIds.length; _i++){
        int _widId = appWidgetIds[_i];

        COUNT+=1;

        RemoteViews _views = new RemoteViews(context.getPackageName(), R.layout.widgetlayout);
        _views.setTextViewText(R.id.tvCount,String.valueOf(COUNT));

        appWidgetManager.updateAppWidget(_widId, _views);
    }
}
}

My Manifest

<receiver android:name="Testwidget">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE"></action>
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/widgetinfo"></meta-data>
    </receiver>

Appwidget Provider

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="272dp" android:minHeight="72dp"
android:updatePeriodMillis="1800020" android:initialLayout="@layout/widgetlayout">

</appwidget-provider>
3
Provide some code what have you tried? - user370305
can you try 1800 for update? and see what happens. - user370305
what is android:updatePeriodMillis? Is it Milliseconds? If yes then 30 minutes = 1800000 milliseconds. Google also shows the same in "30 minutes to milliseconds" - Bhavin Mistry
1800 is not working, I am trying with 180000. - Bhavin Mistry

3 Answers

3
votes

You are using the correct number for miliseconds.

But there is no guarantee that the update will happen at exactly this time interval - it could be delayed by the OS (from the documentation: "The actual update is not guaranteed to occur exactly on time with this value")

2
votes

If you are not using any service it will be update after the miliseconds you have defined, to use service or complete refernce how widget works look here.

0
votes

Minimum of update seconds is 1800000 (30 minutes). From there on the counter is set back to 0 so you have to wait another 30 minutes. Look at the link Pawan leaved behind.