title: Android Widgets w/ AdapterViewFlipper - Pending Intent Template does not get filled in with extras
body: <p>I am making an Android homescreen widget populated with content from the net. Getting it setup I was referencing the StackWidget example from google's pages, and some other <a href="https://stackoverflow.com/questions/13828747/start-mainactivity-from-appwidget-doesnt-work">questions regarding the setOnClickFillInIntent() function being used</a>. Despite that, I cannot find out why that the click intent fires without the template getting populated with the filled-in extras.  The extras aren't null. The widget loads and displays content perfectly fine, but it will crash with a NullPointerEx if clicked.</p>
  
  <p>Something I've noticed is that if the click ID <code>widget_capsule_content</code> in the item layout is at the root level (the LinearLayout) of the layout, the intent does not fire at all.  It does fire if it is in its child (the FrameLayout), but the extras get left off. </p>
  
  <p><strong>Layout for widget_capsule.xml - the individual collection items:</strong> - none of these examples are elegant yet.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal"
  android:clickable="true"
  android:focusable="true"
  android:background="@drawable/capsule_bg5"&gt;
  
  &lt;FrameLayout
      android:id="@+id/widget_capsule_content"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="1"
      android:orientation="horizontal"&gt;
  
      &lt;ImageView
          android:id="@+id/widget_thumbnail"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          android:scaleType="centerCrop" /&gt;
      &lt;TextView
          android:id="@+id/capsule_title"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textSize="10sp"
          android:layout_gravity="bottom"
          android:textColor="@color/white_text"
          android:background="#80000000"
          android:text="title"/&gt;
  &lt;/FrameLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Layout for the widget_layout.xml, the collection holder:</strong></p>
  
  <pre><code>&lt;LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginTop="5dp"
  android:orientation="horizontal"&gt;
  &lt;LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1"
      android:orientation="vertical"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="@color/white_text"
          android:textSize="18sp" /&gt;
  
      &lt;AdapterViewFlipper
          android:id="@+id/widget_flipper"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:autoStart="true"
          android:flipInterval="10000"/&gt;
  
      &lt;ImageView
          android:id="@+id/widget_loading"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/widget_loading"/&gt;
  
  &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Relevant Code from the WidgetReceiver</strong> (extends AppWidgetProvider):</p>
  
  <pre><code>@Override
  public void onUpdate(Context context, AppWidgetManager wManager, int[] appWidgetIds){
      //This method is allowed to handle multiple widgets VIA appWidgetId.
      ComponentName thisWidget = new ComponentName(context,
              IHWidgetReceiver.class);
      int[] allWidgetIds = wManager.getAppWidgetIds(thisWidget);
      for (int widgetId : allWidgetIds) {
          //service intent
          Intent sIntent = new Intent(context, IHWidgetService.class);
          sIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
          sIntent.setData(Uri.parse(sIntent.toUri(Intent.URI_INTENT_SCHEME)));
  
          RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                  R.layout.widget_layout);
          remoteViews.setRemoteAdapter(R.id.widget_flipper, sIntent);
  
          // The empty view is displayed when the collection has no items. It should be a sibling
          // of the collection view.
          remoteViews.setEmptyView(R.id.widget_flipper, R.id.widget_loading);
  
          //Pending Intent to prepare individual item clicks
          /*Class&lt;? extends  Activity&gt; startA = IntentUtil.getActivityClass(context, IHDetail.class);
          Intent pI = new Intent(context, startA); //3
          pI.setAction(Intent.ACTION_VIEW);
          pI.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
          pI.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  //3
          pI.setData(Uri.parse(pI.toUri(Intent.URI_INTENT_SCHEME)));
          remoteViews.setPendingIntentTemplate(R.id.widget_flipper,
                  PendingIntent.getActivity(context, 0, pI, PendingIntent.FLAG_UPDATE_CURRENT));*/
  
          //For sake of breakpointing below, this block is made to match the StackViewWidget sample as much as possible.
          //It suffers the same issue as the activity launch behavior above
          Intent pI = new Intent(context, IHWidgetReceiver.class);
          pI.setAction(ACTION_CLICK);
          pI.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
          pI.setData(Uri.parse(pI.toUri(Intent.URI_INTENT_SCHEME)));
          remoteViews.setPendingIntentTemplate(R.id.widget_flipper,
                  PendingIntent.getBroadcast(context, 0, pI, PendingIntent.FLAG_UPDATE_CURRENT));
  
  
          //done
          Log.i("Widget", "Widget Updated");
          wManager.updateAppWidget(widgetId, remoteViews);
          wManager.notifyAppWidgetViewDataChanged(allWidgetIds, widgetId);
  
      }
      super.onUpdate(context, wManager, appWidgetIds);
  } 
  
  @Override
  public void onReceive(Context rContext, Intent rIntent) {
      Ln.e("RECEIVED THING + ");
      AppWidgetManager wManager = AppWidgetManager.getInstance(rContext);
      if (rIntent.getAction().equals(ACTION_CLICK)) {
  
          Toast.makeText(rContext, "Touched view ", Toast.LENGTH_SHORT).show();
              Bundle eBundle = rIntent.getExtras();
              CmsContent content = (CmsContent) eBundle.getSerializable(IHConstants.MS_CONTENT_EXTRA);
              String id = eBundle.getString(IHConstants.MS_ID_EXTRA);
              //trying again without the bundle
              CmsContent content2 = (CmsContent)  rIntent.getSerializableExtra(IHConstants.MS_CONTENT_EXTRA);
              String id2 = rIntent.getStringExtra(IHConstants.MS_ID_EXTRA);
              //breakpointed here. all of the above extras are null. the next line is a NPE
  
               Intent activityIntent = IntentUtil.getDetailIntent(rContext, content2, id2);
              activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              rContext.startActivity(activityIntent);
      }
      super.onReceive(rContext, rIntent);
  }
  </code></pre>
  
  <p><strong>Relevant Code from the WidgetViewsFactory</strong> (implementing RemoteViewsService.RemoteViewsFactory ):</p>
  
  <pre><code>@Override
  public RemoteViews getViewAt(int position) {
      //populate view w/ data
      RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_capsule);
      rv.setTextViewText(R.id.capsule_title, getContent(position).getShortTitle());
      rv.setImageViewBitmap(R.id.widget_thumbnail, getContent(position).getThumbnail());
  
      //intent junk
      Bundle extras = new Bundle();
      Intent act = new Intent();
      //act.putExtra(IHConstants.MS_ID_EXTRA, capsules.get(position).getId());
      //act.putExtra(IHConstants.MS_CONTENT_EXTRA, getContent(position));
      extras.putString(IHConstants.MS_ID_EXTRA, capsules.get(position).getId());
      extras.putSerializable(IHConstants.MS_CONTENT_EXTRA, getContent(position));
      act.putExtras(extras);
  
      Ln.e("content in extras " + capsules.get(position).getId() + " | " + getContent(position).getDetailSection());  
      //Log indicates that the extras were not null when inserted
      rv.setOnClickFillInIntent(R.id.widget_capsule_content, act);
      return rv;
  }
  </code></pre>