title: intent.getIntExtra( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
body: <p>I cant get the id of the clicked widget in onReceive(). Always return 0. Here is my code:</p>
  
  <pre><code>@Override
      public void onReceive(Context context, Intent intent) {
  
          if (intent.getAction().equals(WIDGET_BUTTON)) {
              int widgetId = intent.getIntExtra( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); 
  
              log("WID ID" + widgetId);
  </code></pre>
  
  <p>I take the code form the Android Developers Docs, i dont know why it isnt working..</p>
  
  <hr>
  
  <p><strong>THE ANSWER:</strong></p>
  
  <p>I miss:</p>
  
  <pre><code>AppWidgetManager mgr = AppWidgetManager.getInstance(context);
  </code></pre>
  
  <p>So my code goes like this:</p>
  
  <pre><code>@Override
  public void onReceive(Context context, Intent intent) {
  
      AppWidgetManager mgr = AppWidgetManager.getInstance(context);
      RemoteViews views = new RemoteViews(context.getPackageName(),
              R.layout.widget_main);
  
  
  
  
      if (intent.getAction().equals(WIDGET_BUTTON)) {
          Bundle extras = intent.getExtras();     
          int widgetId = 0;
  
          if (extras != null &amp;&amp; extras.containsKey(AppWidgetManager.EXTRA_APPWIDGET_ID)) 
              widgetId = intent.getIntExtra(mgr.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); 
              log("1 - WID ID" + widgetId);
  </code></pre>