title: onCreate() after finish() in onStop()
body: <p>I have an Android activity that calls <code>finish()</code> inside it's <code>onStop()</code> so when I switch to other activities (including the main menu), the activity will be shut down. Up this point, everything works as expected.</p>
  
  <p>However, when I run the application again, (sometimes, not always) I notice the application runs using the same PID as the previous and it calls <code>onCreate()</code> again. I didn't see any call to <code>onRestart()</code> so I assume that <code>onCreate()</code> call is performed straight after <code>onStop()</code>, which is something that violates the <a href="http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle" rel="nofollow">activity lifecyce</a>. When the app uses a new PID, I can understand why <code>onCreate()</code> is called, that's because this is the beginning of the activity.</p>
  
  <p>Anyone knows why this happen?</p>
  
  <p>A bit about the app I am developing: This is a Unity + Vuforia + Android application. I create  a custom activity because I need to create a native UI on Android (instead of from Unity).</p>
  
  <p>I found a similar issue reported into the Android project: <a href="http://code.google.com/p/android/issues/detail?id=15331" rel="nofollow">http://code.google.com/p/android/issues/detail?id=15331</a> but I am not sure if the cause is the same or not.</p>
  
  <p><strong>update</strong>: From what I see from the log, after the <code>finish()</code> call, there is no call to <code>onDestroy()</code>. However, if the problem I mentioned happens (the activity is started using the same process), there is a call to <code>onDestroy()</code> at the beginning of activity.</p>
  
  <p><strong>update</strong>: Sorry for the late update. Here I show an excerpt of the logcat.</p>
  
  <pre><code>## First run
  
  I/ActivityManager(  265): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=the.app/the.app.UnityAriusActivity bnds=[238,115][351,273] } from pid 423
  I/ActivityManager(  265): Start proc the.app for activity the.app/the.app.UnityAriusActivity: pid=1686 uid=10013 gids={3003, 1006, 1015}
  D/arius   ( 1686): UnityAriusActivity: onStart
  D/arius   ( 1686): UnityAriusActivity: onResume
  
  ## Home button is pressed
  
  I/ActivityManager(  265): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.sonyericsson.home/.HomeActivity } from pid 265
  D/arius   ( 1686): UnityAriusActivity: onPause
  D/arius   ( 1686): UnityAriusActivity: onStop
  
  ## Second run
  
  I/ActivityManager(  265): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=the.app/the.app.UnityAriusActivity bnds=[238,115][351,273] } from pid 423
  
  ## Same process, onStart is called again
  
  D/arius   ( 1686): UnityAriusActivity: onStart
  D/arius   ( 1686): UnityAriusActivity: onResume
  I/ActivityManager(  265): Displayed the.app/the.app.UnityAriusActivity: +500ms
  D/Unity   ( 1686): Creating OpenGL ES 2.0 context (RGB16 565 16/0)
  W/IInputConnectionWrapper(  423): showStatusIcon on inactive InputConnection
  I/QCAR    ( 1686): onSurfaceCreated
  
  ## Strangely, there's an onDestroy here
  
  D/arius   ( 1686): UnityAriusActivity: onDestroy
  
  ## Unity apparently kills the process from its onDestroy
  
  I/Process ( 1686): Sending signal. PID: 1686 SIG: 9
  I/ActivityManager(  265): Process the.app (pid 1686) has died.
  </code></pre>
  
  <p>The problem is that, there's an <code>onDestroy()</code> after <code>onStart()</code> on the second run. My activity is basically a subclass of Vuforia/QCAR activity which is also a subclass of activity from Unity. So, inside my <code>onDestroy()</code>, I make a call to the superclass' (<code>super.onDestroy()</code>) and also the same for the other methods that I override.</p>
  
  <p>If I looked at the Unity and Vuforia/QCAR Android library (I was curious so I decompiled them -- yeah this may be not right), inside Unity's <code>onDestroy()</code>, Unity tries to kill its own process (which is the application process).</p>
  
  <pre><code>Process.killProcess(Process.myPid());
  </code></pre>
  
  <p>So, when this happens, my app just shut down again. If the second run uses different process, that strange <code>onDestroy()</code> does not happen.</p>
  
  <p>I have also tried the noHistory approach. But the same thing still happens :( When the second run uses the same process, a late <code>onDestroy()</code> will appear and then the process is kill by Unity.</p>