0

I have an issue with the Android app I'm developing which makes the system run 2 processes of the same app when I press the "up" action bar button in one particular activity.

To be more specific, let's call that activity Z and its parent, as declared in the manifest, Y. If I start the activity Z from an activity X and press the up action bar button, the activity Y will be started and then I'll have 2 processes running: one with activity Y and another with Z.

I've already tried setting different launch flags for that activity but the issue persists.

This activity in question shares the same task affinity as 5 others in the app but it's the only one that seems to cause this behaviour.

Here is a snippet of my manifest with the activities in the same affinity as the one causing the issue and a screenshot proving that there are 2 processes of the app running.

Manifest

        <activity android:name=".feature.stations.X"
            android:taskAffinity="@string/affinity_petrol_stations"
            android:theme="@style/AppTheme.NoActionBar"/>

        <activity android:name=".feature.stations.Y"
            android:taskAffinity="@string/affinity_petrol_stations"
            android:theme="@style/AppTheme.NoActionBar">
            <meta-data android:name="android.support.PARENT_ACTIVITY"
                android:value=".feature.stations.X"/>
        </activity>

        <!-- THIS IS THE ACTIVITY THAT CAUSES THE ISSUE -->
        <activity android:name=".feature.stations.Z"
            android:taskAffinity="@string/affinity_petrol_stations"
            android:theme="@style/AppTheme.NoActionBar">
            <meta-data android:name="android.support.PARENT_ACTIVITY"
                android:value=".feature.stations.Y"/>
        </activity>

Screenshot 2 processes running

The process at the top shows activity Z and the one at the bottom shows Y.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
92AlanC
  • 1,327
  • 2
  • 14
  • 33
  • These are "tasks", not processes. In Android an "process" is an operating system thing. You can see different processes by using `adb shell ps` command. Based on the code you've shown you should not end up with 2 different tasks, since all activities share the same task affinity. – David Wasser Oct 02 '18 at 11:29

1 Answers1

0

I managed to solve my problem by removing the meta-data tag from that activity and then implementing manually the up button behaviour like the example below:

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
    when (item?.itemId) {
        ...
        android.R.id.home -> finish()
    }
    return super.onOptionsItemSelected(item)
}
92AlanC
  • 1,327
  • 2
  • 14
  • 33