Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5819] Cannot change launchMode for Android in tiapp.xml

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDuplicate
Resolution Date2018-08-01T13:47:51.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, titanium
ReporterYahya Uddin
AssigneeShak Hossain
Created2018-07-31T22:05:58.000+0000
Updated2018-08-02T19:27:29.000+0000

Description

Whenever I add android:launchMode="singleTask" to the main activity of the application in tiapp.xml, and build the application, it does not appear in the compiled AndroidManifest.xml. To reproduce the issue:

Create a new project

Build to generate initial AndroidManifest.xml file: appc ti run -b -p android

Open the generated build/android/AndroidManifest.xml and copy the first <activity> tree to the tiapp.xml under ti:app/android/manifest/application. You will need to create the empty <manifest> and <application> elements yourself.

Add android:launchMode="singleTask" to the element and save tiapp.xml.

Re-build the app using: appc ti run -b -p android

Open the generated build/android/AndroidManifest.xml, and you will see the android:launchMode="singleTask" was not added.

Here is an example of how the tiapp.xml file will look something like:
<?xml version="1.0" encoding="UTF-8"?>
<ti:app
        xmlns:ti="http://ti.appcelerator.org">
    <name>Sandbox</name>
    <!-- ... -->
    <android
            xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest android:versionCode="3" android:versionName="2.0.0.0">
            <application android:debuggable="true" android:icon="@drawable/appicon" android:label="Sandbox"
                         android:name="SandboxApplication" android:theme="@style/Theme.AppCompat">
                <activity android:name=".SandboxActivity" android:label="@string/app_name"
                          android:theme="@style/Theme.Titanium"
                          android:configChanges="keyboardHidden|orientation|fontScale|screenSize|smallestScreenSize|screenLayout|density"
                          android:launchMode="singleTask">
                </activity>
            </application>
        </manifest>
    </android>
    <!-- ... -->
</ti:app>

Comments

  1. Joshua Quick 2018-08-01

    This is not a bug. Titanium purposely ignores the "launchMode" setting. Attempting to set it will output the following build warning...
       [WARN] : android:launchMode should not be used. Ignoring definition from <ActivityName>
       
    The reason is because there is a lot of confusion about how Google's "singleTask" feature works. When using "singleTask", the Android OS will automatically close all child windows and display the root window when resuming your app. This is the OS' behavior and not Titanium's behavior. In a Titanium app, the root singleTask window is the splash-screen window. So, all Titanium windows you've opened in JavaScript will have been closed. (Again, we have no control over this behavior.) We do offer an alternative solution via our "tiapp.xml" intent-filter-new-task property. Please see the following... https://github.com/appcelerator/titanium_mobile/pull/8897
  2. Yahya Uddin 2018-08-01

    I see. Thank you for your help, but I would consider updating the documentation in Ti.nfc examples: https://github.com/appcelerator-modules/ti.nfc/blob/master/android/example/TagViewer/app/controllers/index.js
  3. Yahya Uddin 2018-08-01

    Please note that I have added
       <property name="intent-filter-new-task" type="bool">false</property>
       
    as a child element to ti:app, but when I scan an NFC tag using the example shown above, it opens a new instance of the app with the app name as "NFC Service". What am I doing wrong?
  4. Rene Pot 2018-08-01

    [~yahya12] this documentation should be more up to date, can you follow this: https://docs.appcelerator.com/platform/latest/#!/api/Modules.Nfc
  5. Rene Pot 2018-08-01

    Also marked this as duplicate as AC-5820 seems to be the same issue.
  6. Yahya Uddin 2018-08-01

    Yes I have looked at the doc also, and it doesn't solve the issue.
  7. Joshua Quick 2018-08-02

    Due to popular demand, we plan on making "launchMode" settable in Titanium 7.3.0 GA. Please see: [TIMOB-26250] I've also posted code on how to deal with "singleTask" mode here... https://github.com/appcelerator/titanium_mobile/pull/10225 The key thing here is that "singleTask" mode will automatically close all child windows when resumed. What you're supposed to do is listen for the "newIntent" event from the root singleTask activity, which you can acquire on app startup. When a new intent has been received, you should display UI related to that intent.

JSON Source