title: Issues re-starting a finish()ed android activity
body: <p>I have two android activities with one single button on both.  </p>
  
  <p>The activity <code>DetailsActivity</code> is my <code>MAIN</code> activity.  </p>
  
  <pre><code>public class DetailsActivity extends Activity {
  
      @Override
      public void onCreate(Bundle bundle) {
  
          super.onCreate(bundle);
          setContentView(R.layout.details_activity_layout);
      }
  
      @Override
      public void onResume() {
  
          super.onResume();
      }
  
  
  
      public void gotoSubDetails(View view) {
  
          Intent intent = new Intent(this, SubDetailsActivity.class);
          startActivity(intent);
          finish();
      }
  } 
  </code></pre>
  
  <p>And my <code>SubDetailsActivity</code> is as follows:  </p>
  
  <pre><code>public class SubDetailsActivity extends Activity {
  
      @Override
      public void onCreate(Bundle bundle) {
  
          super.onCreate(bundle);
          setContentView(R.layout.sub_details_activity_layout);
      }
  
      @Override
      public void onResume() {
  
          super.onResume();
      }
  
  
  
      public void gotoDetails(View view) {
  
          Intent intent = new Intent(this, DetailsActivity.class); 
          startActivity(intent); // Restarting the finish()ed activity here.
          finish();
      }
  } 
  </code></pre>
  
  <p>And this is how I mentioned my button in <code>details_activity_layout.xml</code> for <code>DetailsActivity.java</code>:  </p>
  
  <pre><code>    &lt;Button android:id="@+id/details_submit"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/to_sub_details"
          android:onClick="gotoSubDetails" /&gt;    
  </code></pre>
  
  <p>And this is how I have mentioned my button in <code>sub_details_activity_layout.xml</code> for <code>SubDetailsActivity.java</code>:  </p>
  
  <pre><code>    &lt;Button android:id="@+id/sub_details_submit"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/back_to_details"
          android:onClick="gotoDetails" /&gt;    
  </code></pre>
  
  <p>These are my both activities in <code>AndroidManifest.xml</code>:  </p>
  
  <pre><code>    &lt;activity android:name="DetailsActivity"&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="SubDetailsActivity"&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>When I click the <code>button</code> in <code>DetailsActivity</code>, the activity <code>finish()</code>es properly and <code>SubDetailsActivity</code> starts up.  </p>
  
  <p>But when I click the <code>button</code> in <code>SubDetailsActivity</code> to get back to the <code>finish()</code>ed <code>DetailsActivity</code>, the app straight away crashes on my LG L90 phone.  </p>
  
  <p>Where am I going wrong? Any help? Please.  </p>
  
  <p><b>PS:</b>
  I cannot post the log cat report as I did not test it on my mac but directly on my phone. I don't have an emulator. I am compiling the code on my terminal and transferring the <code>.apk</code> file on my phone via bluetooth.  </p>
  
  <p><b>EDIT:</b>
  Ok guys. Now this is really funny!  </p>
  
  <p>I removed the  </p>
  
  <pre><code>android:onClick="gotoSubDetails"  
  </code></pre>
  
  <p>and  </p>
  
  <pre><code>android:onClick="gotoDetails"  
  </code></pre>
  
  <p>from my <code>details_activity_layout.xml</code> and <code>sub_details_activity_layout.xml</code> respectively. And I loaded the <code>android.widget.Button</code>'s in my <code>DetailsActivity.java</code> and <code>SubDetailsActivity.java</code> and added an <code>android.view.View.OnClickListener</code> on both of them and overrode the <code>onClick(View)</code> method.  </p>
  
  <p>This is what I did in my <code>DetailsActivity.java</code>:  </p>
  
  <pre><code>public class DetailsActivity extends Activity {
  
      @Override
      public void onCreate(Bundle bundle) {
  
          super.onCreate(bundle);
          setContentView(R.layout.details_activity_layout);
  
          Button button = (Button)findViewById(R.id.details_submit);
          button.setOnClickListener(new DetailsSubmitListener());
      }
  
      @Override
      public void onResume() {
  
          super.onResume();
      }
  
  
      public class DetailsSubmitListener implements OnClickListener {
  
          @Override
          public void onClick(View view) {
  
              Intent intent = new Intent(this, SubDetailsActivity.class);
              startActivity(intent);
              finish();
          }
      }
  }  
  </code></pre>
  
  <p>And this is what I did in my <code>SubDetailsActivity.java</code> class:  </p>
  
  <pre><code>public class SubDetailsActivity extends Activity {
  
      @Override
      public void onCreate(Bundle bundle) {
  
          super.onCreate(bundle);
          setContentView(R.layout.details_activity_layout);
  
          Button button = (Button)findViewById(R.id.sub_details_submit);
          button.setOnClickListener(new SubDetailsSubmitListener());
      }
  
      @Override
      public void onResume() {
  
          super.onResume();
      }
  
  
      public class SubDetailsSubmitListener implements OnClickListener {
  
          @Override
          public void onClick(View view) {
  
              Intent intent = new Intent(this, DetailsActivity.class);
              startActivity(intent);
              finish();
          }
      }
  }  
  </code></pre>
  
  <p>And this <b>miraculously</b> worked fine.  </p>
  
  <p>So what was the problem with the <code>.xml</code> attributes in my layout files? And how different is it from the hardcoded listener in my <code>.java</code> file? This thing has confused me. <code>finish()</code>ed activities can be re-started. Thats what I discovered with my change in the program. Please shed some light of knowledge on this.</p>