title: how can I update android widgets with service in background
body: <p>I have trouble in widgets,and I need you help.
  I want to update widgets in 1 minute.What the way I used is set a timer with alarmmanger to start a service to update widgets.But it doesn't work in the background,only work when the mainactivity is alive.</p>
  <p>following is my codes.</p>
  <p><strong>myWidgetProvider:</strong></p>
  <pre><code>private static final int UPDATE_DURATION = 60 * 1000; 
  
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
      super.onUpdate(context, appWidgetManager, appWidgetIds);
      AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime(),UPDATE_DURATION,createPendingIntent(context));
  
      final int N = appWidgetIds.length;
      for (int i=0; i&lt;N; i++){
          int appWidgetId = appWidgetIds[i];
          RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.quotes_layout);
          views.setTextColor(R.id.quotes_textview,Color.WHITE);
          appWidgetManager.updateAppWidget(appWidgetId,views);
      }
  
  }
  
  
  private PendingIntent createPendingIntent(Context context){
      Intent alarmIntent = new Intent(context,TimerService.class);
  
      PendingIntent pendingIntent = PendingIntent.getService(context,0,alarmIntent,PendingIntent.FLAG_UPDATE_CURRENT);
      return pendingIntent;
  }
  
  
  @Override
  public void onDisabled(Context context) {
      super.onDisabled(context);
  
      AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      manager.cancel(createPendingIntent(context));
  }
  </code></pre>
  <p><strong>myService:</strong></p>
  <pre><code>@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      //Internet request and update widgets
  
      return super.onStartCommand(intent, flags, startId);
  }
  </code></pre>