title: How can go in last activity with resume button?
body: <p>My app works fine, but my purpose is that when I close the app then run it again, my app opens at the last activity. I want when I open again main activity become to show and if I clicked resume then last activity open. So I have 4 <code>Activity</code> called <code>Main Activity (my main)</code> , <code>p1</code> ,<code>p2</code>, <code>p3</code>:</p>
  
  <p>Main Activity:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main_page);
  
  
  
          Button resume=(Button)findViewById(R.id.resume);
          Button next=(Button)findViewById(R.id.next);
          Button exit=(Button)findViewById(R.id.exit);
  
          resume.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
  
                  if (!isTaskRoot()
                          &amp;&amp; getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
                          &amp;&amp; getIntent().getAction() != null
                          &amp;&amp; getIntent().getAction().equals(Intent.ACTION_MAIN)) {
  
                      finish();
                      return;
                  }
  
  
              }
          });
  
          next.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(MainActivity.this, p1.class);
                  startActivity(intent);
            }
        });
  
          exit.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  moveTaskToBack(true);
                  android.os.Process.killProcess(android.os.Process.myPid());
                  System.exit(1);
  
              }
          });
  
  
      }
  }
  </code></pre>
  
  <p>XML layout :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;Button
          android:text="resume"
          android:layout_width="wrap_content"
          android:id="@+id/resume"
          android:layout_height="wrap_content" /&gt;
  
      &lt;Button
          android:text="next"
          android:id="@+id/next"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
      &lt;Button
          android:id="@+id/exit"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="exit"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>p1:</p>
  
  <pre><code>public class p1 extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.p1);
  
          Button next = (Button) findViewById(R.id.next);
          Button home=(Button)findViewById(R.id.home);
  
          next.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent=new Intent(p1.this,p2.class);
                  startActivity(intent);
  
              }
          });
  
          home.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent=new Intent(p1.this,MainActivity.class);
                  startActivity(intent);
  
              }
          });
  
          }
      }
  </code></pre>
  
  <p>p1 XML layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;Button
          android:text="next"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/next"/&gt;
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="page 1"/&gt;
      &lt;Button
          android:text="go in main"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/home"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and p2, p3 like p1  </p>
  
  <p>for example :    when I am in p2 then click in go to main and in main when click exit and re run my app , my app open in p2 i want when i re run app main activity open if i clicked resume then p2 come to show.</p>