Problem: Created "hello world" app, tapped the "TAP" button a few times, to see that my apps state has changed, minimized it, clicked its icon again, but instead of resuming activity, it restarted the whole app.
Steps to reproduce:
tns create test --ng
Tested on 3 phones - API17, API22 and API 25.
This problem only occurs in API17 release mode.
tns --version
= 2.4.2
If I minimize the app and resume its activity from the app-stack window, it resumes as it should.
Hi @dxshindeo,
I reviewed your case and found that this behavior has been related with Android. When you suspend your app and click on the icon to resume it, the OS will launch the root activity of the app again and will bringing the existing task to the foreground. More about the problem could be found here. As a solution you could add alwaysRetainTaskState
and launchMode
in your AndroidManifest.xml
file, which set up your app to use the same instance of the activity instead of creating new one. For further help you could review the below-given instructions.
<app_name>/app/App_Resources/Android/AndroidManifest.xml
fileandroid:alwaysRetainTaskState="true"
android:launchMode="singleTask"
Result:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LaunchScreenTheme"
android:alwaysRetainTaskState="true"
android:launchMode="singleTask">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
Hope this helps.
Regards,
@tsonevn
Thank you!!! It worked!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Hi @dxshindeo,
I reviewed your case and found that this behavior has been related with Android. When you suspend your app and click on the icon to resume it, the OS will launch the root activity of the app again and will bringing the existing task to the foreground. More about the problem could be found here. As a solution you could add
alwaysRetainTaskState
andlaunchMode
in yourAndroidManifest.xml
file, which set up your app to use the same instance of the activity instead of creating new one. For further help you could review the below-given instructions.<app_name>/app/App_Resources/Android/AndroidManifest.xml
fileResult:
Hope this helps.
Regards,
@tsonevn