title: How send data from application to AppWidgetProvider?
body: <p>I am stuck in a particular scenario. I need to get my widget updated as soon as the user update the time from the app. I did try Broadcast by sending the data through Intent Extras but fail to do so. Currently, I have my data in <code>AppWidgetProvider</code> and I need to send this data to service</p>
  <pre><code>public class CountdownWidget extends AppWidgetProvider {
      // SharedPreferences userDefaults;
  
      // update rate in milliseconds
      public static final int UPDATE_RATE = 1800000; // 30 minute
  
      public static String nameOne = &quot;&quot;;
  
      @Override
      public void onDeleted(Context context, int[] appWidgetIds) {
          for (int appWidgetId : appWidgetIds) {
              setAlarm(context, appWidgetId, -1);
          }
          super.onDeleted(context, appWidgetIds);
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
  
          Bundle extras = intent.getExtras();
          nameOne = extras.getString(&quot;NAME_ONE&quot;);
  
          Log.e(&quot;Name: &quot;, nameOne);
  
          super.onReceive(context, intent);
      }
  
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                           int[] appWidgetIds) {
  
          for (int appWidgetId : appWidgetIds) {
              setAlarm(context, appWidgetId, UPDATE_RATE);
          }
          super.onUpdate(context, appWidgetManager, appWidgetIds);
      }
  
      public static void setAlarm(Context context, int appWidgetId, int updateRate) {
  
          // Log.e(&quot;&quot;, &quot;Updating Widget Service&quot;);
  
          PendingIntent newPending = makeControlPendingIntent(context,
                  CountdownService.UPDATE, appWidgetId);
          AlarmManager alarms = (AlarmManager) context
                  .getSystemService(Context.ALARM_SERVICE);
          if (updateRate &gt;= 0) {
              alarms.setRepeating(AlarmManager.ELAPSED_REALTIME,
                      SystemClock.elapsedRealtime(), updateRate, newPending);
          } else {
              // on a negative updateRate stop the refreshing
              alarms.cancel(newPending);
          }
      }
  
      public static PendingIntent makeControlPendingIntent(Context context,
                                                           String command, int appWidgetId) {
          Intent active = new Intent(context, CountdownService.class);
          active.setAction(command);
          active.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
          // this Uri data is to make the PendingIntent unique, so it wont be
          // updated by FLAG_UPDATE_CURRENT
          // so if there are multiple widget instances they wont override each
          // other
          Uri data = Uri.withAppendedPath(
                  Uri.parse(&quot;countdownwidget://widget/id/#&quot; + command
                          + appWidgetId), String.valueOf(appWidgetId));
          active.setData(data);
          return (PendingIntent.getService(context, 0, active,
                  PendingIntent.FLAG_UPDATE_CURRENT));
      }
  }
  </code></pre>
  <p>As you see <code>nameOne</code> is a static variable. I can receive data on the <code>onReceive</code> method using getExtras, but I am not unable to pass this data to my <code>CountdownService</code> Service.</p>
  <p>I did try <code>CountdownWidget.nameOne</code> but still fails to fet the data in the service.</p>
  <p>Any help will be highly appreciated.</p>