title: Update widget from an Activity and set it clickable doesn't work
body: <p>I try to make a configuration Activity that updates a widget. I also want to make the widget clickable. I managed to update the widget but it won't let me click on it (nothing happend).</p>
  <p>This is my code.</p>
  <pre><code>private void generate() {
  
      // Create an Intent to launch WidgetConfigurationActivity screen
      Intent intent = new Intent(context, ConfigureWidgetActivity.class);
  
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
  
      // This is needed to make this intent different from its previous intents
      intent.setData(Uri.parse(&quot;tel:/&quot; + (int) System.currentTimeMillis()));
  
      // Creating a pending intent, which will be invoked when the user
      // clicks on the widget
      PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
              intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
      // Getting an instance of WidgetManager
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
  
      // Instantiating the class RemoteViews with widget_layout
      RemoteViews views = new RemoteViews(getBaseContext().getPackageName(), R.layout.widget_layout);
  
      //  Attach an on-click listener to the widget
      views.setOnClickPendingIntent(R.id.widget, pendingIntent);
  
      // Tell the AppWidgetManager to perform an update on the app widget
       appWidgetManager.updateAppWidget(mAppWidgetId, views);
  
      //-----BROADCAST
      Intent refreshIntent = new Intent(this, WidgetProvider.class);
      refreshIntent.putExtra(&quot;parser&quot;, parser);
      sendBroadcast(refreshIntent);
      //-----
      
      // Return RESULT_OK from this activity
      Intent resultValue = new Intent();
      resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
      setResult(RESULT_OK, resultValue);
      finish();
  }
  </code></pre>
  <p>Now, if I put this piece of code in comment</p>
  <pre><code>Intent refreshIntent = new Intent(this, WidgetProvider.class);
  refreshIntent.putExtra(&quot;parser&quot;, parser);
  sendBroadcast(refreshIntent);
  </code></pre>
  <p>The widget is of course not updated but is clickable.</p>
  <p>When I do</p>
  <pre><code>//----FIRST NOW
  Intent refreshIntent = new Intent(this, WidgetProvider.class);
  refreshIntent.putExtra(&quot;parser&quot;, parser);
  sendBroadcast(refreshIntent);
  
  //----THIS COME AFTER
  //  Attach an on-click listener to the widget
  views.setOnClickPendingIntent(R.id.widget, pendingIntent);
  
  // Tell the AppWidgetManager to perform an update on the app widget
  appWidgetManager.updateAppWidget(mAppWidgetId, views);    
  </code></pre>
  <p>Here is my AppWidgetProvider (in case)</p>
  <pre><code>public class WidgetProvider extends AppWidgetProvider {
  /** https://stackoverflow.com/questions/17434898/sending-data-to-my-homescreen-widget */
  @Override
  public void onReceive(Context context, Intent intent) {
  
      Parser parser = (Parser) intent.getSerializableExtra(&quot;parser&quot;);
  
      final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
      ComponentName name = new ComponentName(context, WidgetProvider.class);
      int[] appWidgetId = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
      final int N = appWidgetId.length;
      if (N &lt; 1)
      {
          return ;
      }
      else {
          int id = appWidgetId[N-1];
          updateWidget(context, appWidgetManager, id , parser);
      }
  }
  
  static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId,
                           Parser parser){
  
      RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      if (parser != null) {
          views.setTextViewText(R.id.regio, parser.getRegio());
          views.setTextViewText(R.id.max, parser.getMax());
          views.setTextViewText(R.id.min, parser.getMin());
          views.setTextViewText(R.id.windf, parser.getWindf());
          views.setImageViewResource(R.id.wind, parser.getWind());
          views.setImageViewResource(R.id.first, parser.getFirst());
          views.setImageViewResource(R.id.second, parser.getSecond());
      }
  
      appWidgetManager.updateAppWidget(appWidgetId, views);
  }
  }
  </code></pre>
  <p>I think it's something stupid :)</p>
  <p>Found something (same code as mine?) - <a href="https://stackoverflow.com/a/7738636/2379208">How to update a widget on app start</a></p>