0

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

Himanshu
  • 13
  • 1
  • 4
  • Are you using INTENT to come out from **B** App?You can just come out from **B** App instead of using intent. System OS will automatically show **A** App in its current state – S.Ambika Jan 29 '20 at 10:16
  • checkout: https://stackoverflow.com/questions/2209513/how-to-start-activity-in-another-application – Bijoy Jan 29 '20 at 10:17
  • S. Ambika, Yes I have to use Intent only, as I need to launch that specific app from another app – Himanshu Jan 29 '20 at 10:21
  • Then you should use `putExtras` along with Intent and handle it on **A** App launcher screen side. – S.Ambika Jan 29 '20 at 10:59
  • S.Ambika, that's secondary part, I'm ofcourse gonna use putExtras, but first challenge is to maintain the state as it is – Himanshu Jan 29 '20 at 11:49
  • @Bijoy, that solution doesn't works – Himanshu Jan 29 '20 at 11:49
  • The code you have should work. You can remove the code you are using to add flags to the launch `Intent`, that isn't necessary. Are you launching either of your apps from an IDE (Android Studio)? How are you launching the apps? – David Wasser Feb 03 '20 at 17:09

0 Answers0