Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-27271

Android: Resuming with intent using "FLAG_ACTIVITY_MULTIPLE_TASK" can hang the app

    Details

    • Story Points:
      8
    • Sprint:
      2019 Sprint 16, 2019 Sprint 17

      Description

      Summary:
      Resuming an app with an intent having 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:

      1. Create a classic Titanium app.
      2. Set project name to "IntentTest". (This is <name/> in "tiapp.xml".)
      3. Set project's "Application Id" to "com.appc.intent.test". (This is <id/> in "tiapp.xml".)
      4. Set up the "app.js" with the below code.
      5. Build and run on Android.
      6. Open the Mac "Terminal".
      7. CD (change directory) to: ~/Library/Android/sdk/platform-tools
      8. 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.)

        Attachments

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Gary Mathews
              Tester:
              Keerthi Mahalingam (Inactive)
            • Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Integration