title: Android - Wrong activity sometimes starts
body: <p>I have an Android App with a number of activities. The wrong activity is being started sometimes.</p>
  
  <p>Normally, an Application subclass starts, then start activity (<strong>StartAct</strong>... android:name="android.intent.action.MAIN", android:name="android.intent.category.LAUNCHER")
  does some work and then launches <strong>InitializeActivity</strong>. This does some work and then fires off my main display activity (<strong>MainAct</strong>). The first two activities do some essential initialization including setting a static "<strong>isInitialized</strong>" flag just before the intent is launched for the <strong>MainAct</strong>.</p>
  
  <p>Activities are launched with startActivity() using a specific intent (...activity.class specified), and call finish() after startActivity().</p>
  
  <p>However, here is what sometimes happen, and I don't know why... </p>
  
  <p>In short, the app is killed and when the icon is pressed to start it, it jumps straight to the third (<strong>MainAct</strong>) activity. This causes the app to detect an error (<strong>isInitialized</strong> flag is false) and stop:</p>
  
  <ul>
  <li>Launch the app normally with the Icon:</li>
  <li>...Application subclass starts, also fires up some worker threads</li>
  <li>...<strong>StartActivity</strong> runs, then fires <strong>InitializeActivity</strong> and finishes</li>
  <li>...<strong>InitializeActivity</strong> runs, then sets <strong>isInitialized</strong> and starts <strong>MainAct</strong> and finishes</li>
  <li>...<strong>MainAct</strong> starts, runs okay</li>
  <li>...Home button is hit and Angry Birds is run</li>
  <li>...<strong>MainAct</strong> logs <strong>onPause</strong>, then <strong>onStop</strong>. </li>
  <li>...Worker threads owned by Application subclass continue to periodically do stuff and log.</li>
  <li>After 25 minutes, the entire application is suddenly killed. This observation is based on thhe end of logging activity, </li>
  <li>Time goes by</li>
  <li>Home button hit</li>
  <li>Launcher ICON is pressed for the app</li>
  <li>Application subclass <strong>onCreate</strong> is called and returns</li>
  <li>*<strong><em>MainAct.onCreate</strong> is called! (no <strong>StartAct</strong>, no <strong>InitializeActivity</strong>)</em>*</li>
  </ul>
  
  <p>What am I missing?</p>
  
  <p>Note: the initialize flag was added because of this issue. It is set in the only place in the code that starts the main activity, and checked only in onCreate in the main activity.</p>
  
  <p>[per request]
  Manifest file (slightly redacted). Note that the service in here is not currently used.</p>
  
  <pre><code>&lt;manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.yyy.zzz"
    android:versionCode="1" android:versionName="1.0.1"&gt;
    &lt;application
      android:icon="@drawable/icon_nondistr"
      android:label="@string/app_name"
      android:name=".app.MainApp"
      android:debuggable="true"&gt;
      &lt;activity
        android:label="@string/app_name"
        android:name=".app.StartAct" android:theme="@android:style/Theme.NoTitleBar"&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:label="Html"
        android:name=".app.HtmlDisplayAct"/&gt;
      &lt;activity
        android:label="Init"
        android:configChanges="orientation"
        android:name=".app.InitializeActivity" android:theme="@android:style/Theme.NoTitleBar"/&gt;
      &lt;activity
        android:label="MyPrefs"
        android:name=".app.PrefsAct" /&gt;
      &lt;activity
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar"
        android:name=".app.MainAct"&gt;
      &lt;/activity&gt;
      &lt;service
        android:name=".app.svcs.DataGetterService" /&gt;
    &lt;/application&gt;
    &lt;uses-sdk android:minSdkVersion="4"/&gt;
    &lt;uses-permission
      android:name="android.permission.INTERNET" /&gt;
    &lt;uses-permission
      android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission
      android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
    &lt;uses-permission
      android:name="com.android.vending.CHECK_LICENSE" /&gt;
    &lt;uses-feature
      android:name="android.hardware.location.network"
      android:required="false" /&gt;
  &lt;/manifest&gt;
  </code></pre>