1. Download our Official Android App: Forums for Android!

Apps Android widget automatic update

Discussion in 'Android Development' started by mango_89, Jan 4, 2015.

  1. mango_89

    mango_89 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jan 4, 2015

    Jan 4, 2015
    3
    0
    5
    Male
    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 (Text):
    1. @Override
    2.     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    3.  
    4.     final int N = appWidgetIds.length;
    5.     int appWidgetId = -99;
    6.     for(int i=0; i<N;i++)
    7.     {
    8.         appWidgetId = appWidgetIds[i];
    9.     }
    10.  
    11.  
    12.     RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    13.     Intent intent = new Intent(context,WidgetProvider.class);
    14.     intent.setAction("android.appwidget.action.APPWIDGET_STARTDAY");
    15.  
    16.     PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    17.     views.setOnClickPendingIntent(R.id.buttonStartEndDay, pendingIntent);
    18.  
    19.     appWidgetManager.updateAppWidget(appWidgetIds, views);
    20. }
    21.  
    22. @Override
    23. public void onReceive(Context context, Intent intent) {
    24.  
    25.     if(action.equals("android.appwidget.action.APPWIDGET_STARTDAY"));
    26.     {
    27.         RemoteViews views1 = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    28.         ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);
    29.  
    30.         ...MY CODE...
    31.  
    32.         AppWidgetManager manager = AppWidgetManager.getInstance(context);
    33.         manager.updateAppWidget(thisWidget, views1);
    34.  
    35.     }
    36.     super.onReceive(context, intent);
    37. }
     

    Advertisement

Share This Page

Loading...