[TIMOB-26099] Android: CLI "appc run" should launch app with intent action MAIN category LAUNCHER
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Resolved |
Resolution | Duplicate |
Resolution Date | 2018-06-06T22:05:09.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | android, appc, cli, intent, run |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2018-06-05T22:28:13.000+0000 |
Updated | 2018-06-06T22:05:09.000+0000 |
Description
*Summary:*
Build and run the below code on Android either via Appcelerator Studio or via
appc run
launches the app on Android with an intent that is missing action "android.intent.action.MAIN" and category "android.intent.category.LAUNCHER", which is how an app is normally launched on Android via the app list screen.
The consequence of this is that if you press the HOME button to suspend the app and then tap on the app from the home screen, then a new activity instance will be created and Titanium will be stuck on the splash screen since Titanium only supports running 1 JavaScript runtime at a time.
*Steps to reproduce:*
Build and run the below code on Android either via Appcelerator Studio or via appc run
at the terminal.
Wait for the app to be displayed on the Android device.
Press the "Home" button to suspend the app. (Do *NOT* press the "Back" key.)
From the home screen, go to the app list screen.
Tap on the installed app to attempt to resume it.
After doing this, notice that the app is stuck displaying the splash screen. It does not resume the app. It has created a new activity instance without a JavaScript runtime.
var window = Ti.UI.createWindow();
window.add(Ti.UI.createLabel({ text: 'Test' }));
window.open();
*Cause:*
On Android, an existing activity window stack can be resumed when using the same an intent that originally launched it. If given different intent settings for the same activity (such as the case here), then Android will create a new activity instance by default.
*Recommended Solution:*
We need to modify the CLI on how it starts the app via Android "adb" command line tool here...
https://github.com/appcelerator/node-titanium-sdk/blob/master/lib/adb.js#L655
We need to add intent parameters -a
to set the action, -c
to set the category, and -f
to set the flags via adb similar to the following.
./adb shell am start -n <PackageName>/.<ActivityName> -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000
The -f 0x10200000
part adds intent flags FLAG_ACTIVITY_NEW_TASK
and FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
. The FLAG_ACTIVITY_NEW_TASK
is set by all Android OS versions when launching an app from the home screen. The FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
is set by newer Android OS versions (such as Android 8) but works fine on older OS versions such Android 4.1.
*Note:*
We also need this change to resolve a regression mentioned here: [TIMOB-25867]
PR: https://github.com/appcelerator/node-titanium-sdk/pull/30
Marking as Duplicate of TIMOB-25867 to handle the regression fix there as well.