Not sure if this gonna be answered by another thread, but for awhile of seeking the answer, i didn't found one.
I'm implement an app widget to display some text every 30mn, but it didn't update until I click on the widget. Here is my onUpdate methode :
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
// Get all ids
ComponentName thisWidget = new ComponentName(context, MyWidgetProvider.class);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
Calendar getToday = Calendar.getInstance();
for (int widgetId : allWidgetIds)
{
int number = (new Random().nextInt(100));
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
// Set the text
String n = ""+number;
remoteViews.setTextViewText(R.id.update, n);
remoteViews.setTextColor(R.id.update, Color.BLUE);
// Register an onClickListener
Intent intent = new Intent(context, MyWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
What's the problem with my code ? Can anybody help me out. thanks in advance
Added :
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:updatePeriodMillis="110000"
android:initialLayout="@layout/widget_layout"
android:minHeight="72dp"
android:minWidth="300dp">
</appwidget-provider>