[AC-5819] Cannot change launchMode for Android in tiapp.xml
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Duplicate |
Resolution Date | 2018-08-01T13:47:51.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | android, titanium |
Reporter | Yahya Uddin |
Assignee | Shak Hossain |
Created | 2018-07-31T22:05:58.000+0000 |
Updated | 2018-08-02T19:27:29.000+0000 |
Description
Whenever I add Build to generate initial AndroidManifest.xml file:
Open the generated
Add android:launchMode="singleTask" to the
Re-build the app using:
Open the generated
Here is an example of how the tiapp.xml file will look something like:
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>
This is not a bug. Titanium purposely ignores the "launchMode" setting. Attempting to set it will output the following build warning...
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/8897I 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
Please note that I have added
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?[~yahya12] this documentation should be more up to date, can you follow this: https://docs.appcelerator.com/platform/latest/#!/api/Modules.Nfc
Also marked this as duplicate as AC-5820 seems to be the same issue.
Yes I have looked at the doc also, and it doesn't solve the issue.
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.