Consider there are two Android Native Apps "A" and "B" having Activities as A1, A2, A3 and B1, B2, B3 respectively where A1 and B1 are the Launcher Activities for respective Applications
Use Case: App "A" is Launched and user navigates to A2 from A1 and puts the app in background User now opens App "B" and navigates to B2 from B1. There is a button present on B2 which will open App "A". Here Since the App "A" is in background and on A2 Activity, The App should start from same State, i.e. from A2 only
If App "A" is not in background, then it will start from A1 i.e. the Launcher Activity
Code tried so far
Java Code
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.target");
if (launchIntent != null) {
launchIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(launchIntent);
}
Manifest
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SecondActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
This code is Launching "A" App from the background but doesn't maintains the state and hence starts from the Launcher Activity
Already tried this solution, but doesn't works either https://stackoverflow.com/a/12075313/6617467