• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android widget automatic update

mango_89

Lurker
I am working an android app which also contain a widget part. The widget is built from the two buttons, a few textviews and a one listview. The widget updates every 30min automatically over appwidget-provider.

My problem is that each automatic update, also update the code into onReceive() method and launch process under buttuns.

How to avoid that automatic call onUpdate() will not launch the code under buttons (onReceive())?

Here is my code:


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

    final int N = appWidgetIds.length;
    int appWidgetId = -99;
    for(int i=0; i<N;i++)
    {
        appWidgetId = appWidgetIds[i];
    }


    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    Intent intent = new Intent(context,WidgetProvider.class);
    intent.setAction("android.appwidget.action.APPWIDGET_STARTDAY");

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    views.setOnClickPendingIntent(R.id.buttonStartEndDay, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetIds, views);
}

@Override
public void onReceive(Context context, Intent intent) {

    if(action.equals("android.appwidget.action.APPWIDGET_STARTDAY"));
    {
        RemoteViews views1 = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);

        ...MY CODE...

        AppWidgetManager manager = AppWidgetManager.getInstance(context);
        manager.updateAppWidget(thisWidget, views1);

    }
    super.onReceive(context, intent);
}
 
Back
Top Bottom