title: Navigation problem (with a back button) in an Android app
body: <p>Here is a navigation problem I am having within an Android app.
  I must be missing something very basic, but can't see what.
  Let's hope a new eye will spot the issue.</p>
  <p>The app has three activities: MainActivity, FirstActivity, and SecondActivity.</p>
  <p>And the navigation is meant to go like this:</p>
  <p>MainActivity &lt;-&gt; FirstActivity &lt;-&gt; SecondActivity</p>
  <p>In other words back-and-forth between MainActivity and FirstActivity an also
  back-and-forth between FirstActivity and SecondActivity.
  But with no direct path between MainActivity and SecondActivity.</p>
  <p>Here is the AndroidManifest.xml supposed to translate what I wrote above:</p>
  <pre><code>&lt;application
      android:allowBackup=&quot;true&quot;
      android:dataExtractionRules=&quot;@xml/data_extraction_rules&quot;
      android:fullBackupContent=&quot;@xml/backup_rules&quot;
      android:icon=&quot;@mipmap/ic_launcher&quot;
      android:label=&quot;@string/app_name&quot;
      android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
      android:supportsRtl=&quot;true&quot;
      android:theme=&quot;@style/Theme.MyApp&quot;
      tools:targetApi=&quot;31&quot;&gt;
      &lt;activity
          android:name=&quot;.SecondActivity&quot;
          android:exported=&quot;false&quot;
          android:parentActivityName=&quot;.FirstActivity&quot;
          android:screenOrientation=&quot;portrait&quot; /&gt;
  
      &lt;activity
          android:name=&quot;.FirstActivity&quot;
          android:exported=&quot;false&quot;
          android:parentActivityName=&quot;.MainActivity&quot;
          android:screenOrientation=&quot;portrait&quot; /&gt;
  
      &lt;activity
          android:name=&quot;.MainActivity&quot;
          android:exported=&quot;true&quot;
          android:screenOrientation=&quot;portrait&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  <p>Now running the app the problem is this:</p>
  <p>When I am in the SecondActivity and push the Up button, I expect to go back to the FirstActivity.</p>
  <p>But instead I see some flickering, then a black screen and finally the app goes to the MainActivity.</p>
  <p>What is going on?</p>
  <p>Here is some more detail about the situation.</p>
  <p>This is the code for <em>SecondActivity</em>:</p>
  <pre><code>package me.soft.myapp
  
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  
  class SecondActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_second)
      }
  }
  </code></pre>
  <p>And this is where <em>SecondActivity</em> is fired up inside <em>FirstActivity</em>:</p>
  <pre><code>val axBtn = Button(this)
  ......
  axBtn.setOnClickListener {
      val axIntent = Intent(this, SecondActivity::class.java).apply {
      }
      startActivity(axIntent)
  }
  </code></pre>