Scenario:
- QRCode scan URL scheme
- Open the scanned URL scheme
- Launch Main activity (root)
- Launch Welcome activity (via startActivity, with Intent.FLAG_ACTIVITY_NEW_TASK)
- Launch Welcome activity A (via startActivityForResult)
- Based on onActivityResult, launch Welcome activity B (via startActivityForResult)
- Based on onActivityResult, launch Welcome activity C (via startActivityForResult)
- Finish Welcome activity, back to Main activity.
All activities are using standard launch mode on AndroidManifest.xml
The tasks shown on recent apps stack are 3 items:
- QRCode scanner task
- Main activity task
- Welcome activity task
If we launch app from app icon (not from QRCode scanner), the task shown on recent apps stack has only one task.
Q1: Is there a way to prevent multiple tasks shown on recent apps when launch via QRCode scanner?
Also, we have additional issue where: (no. 4)
- Normal app launch from app icon, able to complete chained process above with no issue.
- Launch app by scanning QRCode, able to complete chained process above with no issue.
- Normal app launch from app icon, when on activity A or activity B screen, suspend the app by pressing "Recent apps" button to see the apps overview, resume back to the app by selecting the app task, able to complete chained process above with no issue.
- Launch app by scanning QRCode, when on activity A or activity B screen, suspend the app by pressing "Recent apps" button to see the apps overview, resume back to the app by selecting the app task, continue chained process, on step 8, the Welcome activity finish is triggered, but it did not switch back to the main activity. On recent apps stacks, we can manually switch to the task with main activity, and able to see the main activity is rendering the page that is supposed to be shown after the chained process is completed.
Q2: Is there a way to ensure when the Welcome activity is finished, always switch back to Main activity? Is this issue related to the first question on multiple tasks shown on recent apps? Without suspending the app, when Welcome activity is finished, it is able to switch back to Main activity though.
QRCode scanner used:
- Barcode Scanner by ZXing Team
- QR & Barcode Scanner by Gamma Play
Manifest: Main manifest (root)
<application
android:name="myApp"
tools:replace="android:allowBackup"
android:allowBackup="false"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:resizeableActivity="false"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity
android:name="com.myapp.MainActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize|layoutDirection|locale"
android:theme="@style/LaunchScreenTheme">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="schemeclient" />
</intent-filter>
</activity>
</application>
library manifest:
<application>
<activity
android:name="WelcomeActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale|layoutDirection" />
<activity
android:name="ActivityA"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LightTheme">
<meta-data
android:name="action_handler"
android:value="com.ui.WelcomeScreenActionHandlerImpl" />
</activity>
<activity
android:name="ActivityB"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LightTheme"/>
<activity
android:name="ActivityC"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LightTheme"/>
</application>