• 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
Jan 4, 2015
3
0
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);
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones