1

I have developed an app in Nativescript Angular for Android and IOS. When I send push notifications to the Android app, and the app is in background, the first notification can be opened without any issue. However if I try to open the second notification, the app crashes with the following error

System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to destroy activity {myapp/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onDestroy failed
System.err: Error: View not added to this instance. View: Frame(274) CurrentParent: undefined ExpectedParent: AppHostView(1)
System.err:
System.err: StackTrace:
System.err: java.lang.RuntimeException: Unable to destroy activity {com.communithings.vrt/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onDestroy failed
System.err: Error: View not added to this instance. View: Frame(274) CurrentParent: undefined ExpectedParent: AppHostView(1)
System.err:     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4204)
System.err:     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4222)
System.err:     at android.app.ActivityThread.-wrap6(ActivityThread.java)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1539)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     at android.os.Looper.loop(Looper.java:154)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6121)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
System.err: Caused by: com.tns.NativeScriptException: Calling js method onDestroy failed
System.err: Error: View not added to this instance. View: Frame(274) CurrentParent: undefined ExpectedParent: AppHostView(1)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1242)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1122)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1109)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1089)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1081)
System.err:     at com.tns.NativeScriptActivity.onDestroy(NativeScriptActivity.java:39)
System.err:     at android.app.Activity.performDestroy(Activity.java:6925)
System.err:     at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1154)
System.err:     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4191)
System.err:     ... 9 more

It looks the app goes to onDestroy and restarts fully when it tries to open the notification. But I only have issues when the second notification is being opened.

My app is using

Nativescript 6.3.0
tns-core-modules has 6.3.2 version
tns-android has 6.3.1 version 
tns-ios has 6.3.0 version 

Any idea on how to fix this?

jht
  • 141
  • 10
  • It looks it works when I added android:launchMode="singleTask" to my AndroidManifest – jht Feb 04 '20 at 14:00

2 Answers2

0

It works when android:launchMode="singleTask" to AndroidManifestis added

jht
  • 141
  • 10
  • "singleTask and singleInstance — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications." https://developer.android.com/guide/topics/manifest/activity-element#lmode – Przemo May 11 '20 at 06:03
0

I think you should wrap your page-router-outlet inside a StackLayout, I encoutered this one, was fixed by doing this:

in your app.component.html:

<StackLayout> 
    <page-router-outlet></page-router-outlet>
</StackLayout>