title: Android remoteViews with buttons , when click the button, the notification bar can not pack up
body: <p>I have customized a <code>notification</code> with the <code>remoteviews</code>, the view contains layouts and two buttons, what I want is that when users click a layout which named "contentLayout", the activity "Test" will be opened, and when Users click  buttons, "remindTenMinButton" or "remindLaterButton", the action "Test2" will started.now the problem is the activity "Test" started correctly, but for the activity "Test2", when I clicked the button in the notification bar, it seems nothing happened, but when I click the "back", when the notification bar fold back, I can see the Test2 has already started, so the question is how to make the notification bar fold back when user click the button in the remoteview?
  below are my codes:</p>
  
  <p><strong>MainActivity</strong>:</p>
  
  <pre><code>package com.example.androidtest2;
  import android.app.Activity;
  import android.app.Notification;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.app.TaskStackBuilder;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.NotificationCompat;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.RemoteViews;
  public class MainActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Button button = (Button) findViewById(R.id.button1);
      button.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                      MainActivity.this).setSmallIcon(R.drawable.ic_launcher);
  
              String notifyTitle = "title....";
  
              String notifyContent = "content......";
  
              RemoteViews remoteViews = new RemoteViews(MainActivity.this
                      .getPackageName(), R.layout.notification_bar);
              remoteViews.setTextViewText(R.id.title, notifyTitle);
              remoteViews.setTextViewText(R.id.content, notifyContent);
  
              Intent resultIntent = new Intent(MainActivity.this, Test.class);
  
              TaskStackBuilder stackBuilder = TaskStackBuilder
                      .create(MainActivity.this);
              stackBuilder.addParentStack(Test.class);
              stackBuilder.addNextIntent(resultIntent);
              PendingIntent resultPendingIntent = stackBuilder
                      .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
  
              Intent notifyLaterIntent = new Intent(MainActivity.this,
                      NotificationProcesssingReceiver.class);
              PendingIntent PendingNotifyLaterIntent = PendingIntent
                      .getBroadcast(MainActivity.this, 0, notifyLaterIntent,
                              PendingIntent.FLAG_CANCEL_CURRENT
                                      | PendingIntent.FLAG_ONE_SHOT);
  
              Intent notify10LaterIntent = new Intent(MainActivity.this,
                      NotificationProcesssingReceiver.class);
              PendingIntent PendingNotify10LaterIntent = PendingIntent
                      .getBroadcast(MainActivity.this, 0,
                              notify10LaterIntent, 0);
  
              remoteViews.setOnClickPendingIntent(R.id.contentLayout,
                      resultPendingIntent);
              remoteViews.setOnClickPendingIntent(R.id.remindLaterButton,
                      PendingNotifyLaterIntent);
              remoteViews.setOnClickPendingIntent(R.id.remindTenMinButton,
                      PendingNotify10LaterIntent);
  
              NotificationManager mNotificationManager = (NotificationManager) MainActivity.this
                      .getSystemService(Context.NOTIFICATION_SERVICE);
  
              Notification notification = mBuilder.build();
              notification.defaults = Notification.DEFAULT_SOUND;
              notification.audioStreamType = android.media.AudioManager.ADJUST_LOWER;
  
              notification.icon = R.drawable.ic_launcher;
  
              notification.tickerText = "ticker text...";
  
              notification.bigContentView = remoteViews;
  
              // mId allows you to update the notification later on.
              mNotificationManager.notify(1, notification);
  
          }
      });
  }
  }
  </code></pre>
  
  <p><strong>NotificationProcesssingReceiver</strong>:</p>
  
  <pre><code>package com.example.androidtest2;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.util.Log;
  
  public class NotificationProcesssingReceiver extends BroadcastReceiver{
   @Override
      public void onReceive(Context context, Intent intent) 
      {
          Intent test = new Intent(context, Test2.class);
          test.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          //context.startActivity(toMainScreen);
          context.startActivity(test);
      }
  }
  </code></pre>
  
  <p><strong>Test</strong>:</p>
  
  <pre><code>public class Test extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_test);
      /* NotificationManager mNotificationManager = (NotificationManager)    getSystemService(Context.NOTIFICATION_SERVICE);
       mNotificationManager.cancel(1);*/
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Test2</strong>:</p>
  
  <pre><code>    public class Test2 extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_test2);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>activity_main.xml</strong>:</p>
  
  <pre><code>   &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="${packageName}.${activityClass}" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" /&gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/textView1"
      android:layout_marginLeft="56dp"
      android:text="Button" /&gt;
        &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>notification_bar.xml</strong>:</p>
  
  <pre><code>     &lt;?xml version="1.0" encoding="utf-8"?&gt;
         &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="100dp" &gt;
  
  &lt;LinearLayout
      android:id="@+id/linearLayout1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:orientation="vertical" &gt;
  
      &lt;RelativeLayout
          android:id="@+id/contentLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;ImageView
              android:id="@+id/imageView1"
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:src="@drawable/desk_command_oye" /&gt;
  
           &lt;LinearLayout
      android:id="@+id/contentTextLayout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_toRightOf="@+id/imageView1"
      android:orientation="vertical" &gt;
      &lt;TextView  android:id="@+id/title"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Title...."/&gt;
       &lt;TextView  android:id="@+id/content"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="text content"/&gt;
      &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
        &lt;LinearLayout
            android:id="@+id/buttonsLayout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/linearLayout1"
      android:layout_toRightOf="@+id/linearLayout1" &gt;
      &lt;Button    android:id="@+id/remindTenMinButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="button1"/&gt;
       &lt;Button    android:id="@+id/remindLaterButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="button2"/&gt;
  &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
          &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>activity_test.xml</strong>:</p>
  
  <pre><code>               &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"  tools:context="${packageName}.${activityClass}" &gt;
         &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" /&gt;
  
     &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>activity_test2.xml:</p>
  
  <pre><code>      &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="${packageName}.${activityClass}" &gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" /&gt;
      &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong>:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.androidtest2"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="16"
      android:targetSdkVersion="19" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.androidtest2.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name="com.example.androidtest2.Test"
          android:label="@string/title_activity_test" &gt;
      &lt;/activity&gt;
  
      &lt;receiver android:name="com.example.androidtest2.NotificationProcesssingReceiver" &gt;
      &lt;/receiver&gt;
  
      &lt;activity
          android:name="com.example.androidtest2.Test2"
          android:label="@string/title_activity_test2" &gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>