title: How to know clicked widget id?
body: <p>I have implemented a <code>widget</code> with an <code>ImageButton</code> and a <code>TextView</code>. That <code>ImageButton</code> launch an <code>activity</code> when its clicked. This <code>activity</code> updates the widget text with what the user writes on the activity <code>EditText</code>. Now the problem is that I only know how to get the ids like this:</p>
  
  <pre><code>for (int widgetId : allWidgetIds) {
          // Create some random data
          int number = (new Random().nextInt(100));
  
          RemoteViews remoteViews = new RemoteViews(getApplicationContext()
                  .getPackageName(), R.layout.widget_layout);
          Log.w("WidgetExample", String.valueOf(number));
  
          //Here I should set text from edit text, but I'm using a random for testing.
  
          remoteViews.setTextViewText(R.id.textView1,
                  "Random: " + String.valueOf(number));
  
          appWidgetManager.updateAppWidget(widgetId, remoteViews);
      }
  </code></pre>
  
  <p>This code will obviously change the data of all the ids, since its inside a <code>for</code>. Is there anyway that I can past the clicked widgetId with my intent, so I can eliminate that <code>for</code>? This is my widgetProvider: </p>
  
  <pre><code>@Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
          int[] appWidgetIds) {
  
      // Get all ids
      ComponentName thisWidget = new ComponentName(context, Widget.class);
      allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
      for (int widgetId : allWidgetIds) {
  
          Intent i = new Intent(context, WidgetSetup.class);
          i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
          i.setFlags(i.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(i);
  
          // Create some random data
          int number = (new Random().nextInt(100));
  
          RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                  R.layout.widget_layout);
          // Set the text
          remoteViews.setTextViewText(R.id.textView1, String.valueOf(number));
  
          Intent active = new Intent(context, Widget.class);
          active.setAction(ACTION_WIDGET_REFRESH);
          PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
          remoteViews.setOnClickPendingIntent(R.id.imageButton1, actionPendingIntent);
  
          active = new Intent(context, Widget.class);
          active.setAction(ACTION_WIDGET_SETTINGS);
          actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
          remoteViews.setOnClickPendingIntent(R.id.imageButton2, actionPendingIntent);
  
          appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
      }
  }
  
  @Override
  public void onReceive(Context context, Intent intent) {
      if (intent.getAction().equals(ACTION_WIDGET_REFRESH)) {
          //Log.i("onReceive", ACTION_WIDGET_REFRESH);
  
          Intent i = new Intent(context, MainActivity.class);
          i.setFlags(i.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(i);
  
      } else if (intent.getAction().equals(ACTION_WIDGET_SETTINGS)) {
          //Log.i("onReceive", AppWidgetManager.EXTRA_APPWIDGET_ID);
  
  
  
          Intent i = new Intent(context, WidgetSetup.class);
          i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
  
          //Here I tried to pass the widgetID with no luck.
          //i.putExtra(pass widget id?);
  
          i.setFlags(i.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(i);
  
      } else {
          super.onReceive(context, intent);
      }
  }
  </code></pre>
  
  <p>Thanks</p>