Search code examples
androidandroid-activityandroid-manifest

Android run 2 activities next to each other in task list


Is it possible within Android to run 2 activities side by side in task manager? I can now generate 2 separate icons and they both work properly but I can only open 1 Window at a time . As soon as I open the other icon, the current one is replaced with the new activity. I would have liked it to have its own screen if possible. I've tried various options but failed. Is it even possible within Android?

This is what my manifest looks like without the adjusments.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.allpics">
    
    ...
    
    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AllPics">

        <activity
            android:exported="true"
            android:name=".MainActivity"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:exported="true"
            android:name=".GalleryActivity"
            android:label="Gallery"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        ...

    </application>

</manifest>

Solution

  • In the AndroidManifest, make sure to set the android:taskAffinity attribute of the element differently for each Activity. For example:

    <activity
        android:name="com.example.ActivityA"
        android:label="Activity A"
        android:launchMode="singleInstance"
        android:taskAffinity="com.example.AffinityA" >
    </activity>
    <activity
        android:name="com.example.ActivityB"
        android:label="Activity B"
        android:launchMode="singleInstance"
        android:taskAffinity="com.example.AffinityB" >
    </activity>