[TIMOB-27271] Android: Resuming with intent using "FLAG_ACTIVITY_MULTIPLE_TASK" can hang the app
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-08-22T14:57:46.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 8.1.1 |
Components | Android |
Labels | android, engSchedule, intent, intent-filter, resume |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2019-07-23T01:40:33.000+0000 |
Updated | 2019-08-22T14:57:46.000+0000 |
Description
*Summary:*
Resuming an app with an intent having Set project name to "IntentTest". _(This is
Set project's "Application Id" to "com.appc.intent.test". _(This is
CD (change directory) to:
FLAG_ACTIVITY_MULTIPLE_TASK
set causes it to hang in Titanium 8.0.0 if the app does not immediately open a window via its "newintent" event.
Titanium 7.x.x and older isn't much better. It won't hang on startup, but will instead create a new splash screen activity instance and do nothing.
*Note:*
The Android OS will automatically add the FLAG_ACTIVITY_MULTIPLE_TASK
to intents assigned the ACTION_SEND
action. So, apps whose intent-filter do not handle "intent-filter" ACTION_SEND
typically don't have to worry about this issue.
*Steps to reproduce:*
Create a classic Titanium app.
Set project name to "IntentTest". _(This is <name/>
in "tiapp.xml".)_
Set project's "Application Id" to "com.appc.intent.test". _(This is <id/>
in "tiapp.xml".)_
Set up the "app.js" with the below code.
Build and run on Android.
Open the Mac "Terminal".
CD (change directory) to: ~/Library/Android/sdk/platform-tools
In the terminal, enter the following...
./adb shell am start -n com.appc.intent.test/.IntenttestActivity -a android.intent.action.VIEW -d https://www.appcelerator.com -f 0x08000000
app.js
Ti.Android.rootActivity.addEventListener("newintent", function(e) {
label.text = "New Intent:\n" + JSON.stringify(e.intent, null, 4);
Ti.API.info("@@@ newintent: " + JSON.stringify(e.intent));
});
var window = Ti.UI.createWindow();
var scrollView = Ti.UI.createScrollView({
scrollType: "vertical",
width: Ti.UI.FILL,
height: Ti.UI.FILL,
});
var label = Ti.UI.createLabel({
text: "Launch Intent:\n" + JSON.stringify(Ti.Android.rootActivity.intent, null, 4),
width: Ti.UI.FILL,
height: Ti.UI.SIZE,
});
scrollView.add(label);
window.add(scrollView);
window.open();
*Result:*
In Titanium 8.0.0 and higher, the app hangs. Also notice in the log that the "newintent" is being logged non-stop, meaning the "newintent" event is being fired repeatedly when it should only be fired once.
In Titanium versions older than 8.0.0, a new splash screen activity window is displayed, but nothing happens. Note that the app is not hung and you can back-out of the splash window, but this is still not good behavior.
*Expected Result:*
The "newintent" event should only be fired once and not hang the app.
*Work-around:*
Immediately open a window when a "newintent" is received set with this flag.
If you don't want to open a window immediately, then you can instead quickly open/close a temporary window when this flag is set. Note that closing a window immediately as shown below prevents it from ever being shown, because Titanium destroys it via the activity's onCreate()
method.
Ti.Android.rootActivity.addEventListener("newintent", function(e) {
// This works-around the issue.
if (e.intent.flags & Ti.Android.FLAG_ACTIVITY_MULTIPLE_TASK) {
var window = Ti.UI.createWindow();
window.open();
window.close();
}
});
_(I've tested the below on Android Q while target API Level 29. It works fine.)_
My initial thought was to set the activity's "android:documentLaunchMode" attribute to "never", which according to Google's docs would make it ignore the
FLAG_ACTIVITY_MULTIPLE_TASK
intent flag. https://developer.android.com/guide/topics/manifest/activity-element#dlmode While this does work and makes it re-use the existing activity (instead of creating a duplicate activity instance), the negative consequence is that the activity is put into a "singleTask" like mode where the Android OS will automatically destroy all child activities when it is started via an intent. This is not a viable option for us. Most app devs don't want "singleTask" like behavior (and they can already opt-in to this behavior if they want anyways).PR (master): https://github.com/appcelerator/titanium_mobile/pull/11080 PR (8.1.x): https://github.com/appcelerator/titanium_mobile/pull/11081
FR Passed. NO hanging when resuming app with an intent having FLAG_ACTIVITY_MULTIPLE_TASK. Works as Expected. Waiting for the 8.1.0 GA release to merge this PR
PR (8.3.x): https://github.com/appcelerator/titanium_mobile/pull/11145
Merged to master, 8_3_X and 8_1_X
*Closing ticket* fix verified in SDK version
8.2.0.v20190820104021
,8.1.1.v20190820143437
and8.3.0.v20190820103430
. Test and other information can be found at: PR (master): https://github.com/appcelerator/titanium_mobile/pull/11080 PR (8.1.x): https://github.com/appcelerator/titanium_mobile/pull/11081 PR (8.3.x): https://github.com/appcelerator/titanium_mobile/pull/11145