Skip to content

App Crashes When Killed While Foreground Service is Active #1082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
knargcr opened this issue Jul 3, 2024 · 5 comments
Closed

App Crashes When Killed While Foreground Service is Active #1082

knargcr opened this issue Jul 3, 2024 · 5 comments

Comments

@knargcr
Copy link

knargcr commented Jul 3, 2024

I am experiencing an issue with my app when it is killed while foreground services are running.

In my app, the entry frame (Antre) navigates to a page (Home) and that page starts the service. When app is killed while the service is on, it skips Antre and opens Home right away. The reopened app does not work as expected. Afterwards, when the app is killed again while service is still running, it crashes with the following error. It seems the navigation stack is not cleared properly

System.err: An uncaught Exception occurred on "main" thread.
  System.err: Unable to destroy activity {org.nativescript.vue3Template/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onDestroy failed
  System.err: TypeError: Cannot read properties of null (reading 'unmount')
  System.err:
  System.err: StackTrace:
  System.err: page.disposeNativeView(file: src/webpack:/vue3Template/node_modules/nativescript-vue/dist/plugins/navigation.js:42:0)
  System.err:   at _tearDownUI(file: src/webpack:/vue3Template/node_modules/@nativescript/core/ui/core/view-base/index.js:814:0)
  System.err:   at (file: src/webpack:/vue3Template/node_modules/@nativescript/core/ui/core/view-base/index.js:789:0)
  System.err:   at eachChildView(file: src/webpack:/vue3Template/node_modules/@nativescript/core/ui/frame/frame-common.js:454:0)
  System.err:   at eachChild(file: src/webpack:/vue3Template/node_modules/@nativescript/core/ui/core/view/view-common.js:819:0)
  System.err:   at _tearDownUI(file: src/webpack:/vue3Template/node_modules/@nativescript/core/ui/core/view-base/index.js:788:0)
  System.err:   at onDestroy(file: src/webpack:/vue3Template/node_modules/@nativescript/core/ui/frame/index.android.js:1073:0)
  System.err:   at onDestroy(file: src/webpack:/vue3Template/node_modules/@nativescript/core/ui/frame/activity.android.js:36:0)
  System.err:   at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5409)
  System.err:   at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5442)
  System.err:   at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:47)
  System.err:   at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
  System.err:   at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
  System.err:   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
  System.err:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
  System.err:   at android.os.Handler.dispatchMessage(Handler.java:106)
  System.err:   at android.os.Looper.loopOnce(Looper.java:201)
  System.err:   at android.os.Looper.loop(Looper.java:288)
  System.err:   at android.app.ActivityThread.main(ActivityThread.java:7872)
  System.err:   at java.lang.reflect.Method.invoke(Native Method)
  System.err:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  System.err:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
  System.err: Caused by: com.tns.NativeScriptException: Calling js method onDestroy failed
  System.err: TypeError: Cannot read properties of null (reading 'unmount')
  System.err:   at com.tns.Runtime.callJSMethodNative(Native Method)
  System.err:   at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1301)
  System.err:   at com.tns.Runtime.callJSMethodImpl(Runtime.java:1187)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1174)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1152)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1148)
  System.err:   at com.tns.NativeScriptActivity.onDestroy(NativeScriptActivity.java:43)
  System.err:   at android.app.Activity.performDestroy(Activity.java:8562)
  System.err:   at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1452)
  System.err:   at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5396)
  System.err:   ... 13 more

The issue gets solved when I comment out the following if-check in node_modules/nativescript-vue/dist/plugins/navigation.js

if (!isReloading) {
       view.unmount();
       view = null;
}

You can find the steps and the repo to reproduce the bug below.

Repository to reproduce

Steps to reproduce the bug

  • Click to open the drawer
  • Kill the app
  • Close the drawer by clicking outside
  • Drawer does not open
  • Kill the app again

Additional context: My app starts a foreground service to get the user's location, and I use Firebase Analytics to handle notifications. This problem occurs on Android 13.

@PixsaOJ
Copy link

PixsaOJ commented Sep 2, 2024

Simmilar: I do not have foreground service.

https://github.com/PixsaOJ/ns-vue-router-unmount-error

  1. Open details
  2. Minimize app
  3. Open app again from opened apps view
  4. swipe back or click back to go back.

I get exact same error.

@PixsaOJ
Copy link

PixsaOJ commented Sep 2, 2024

I think its the same issue, because its not producible if i fully reopen app from app drawer and Error log is the same

@knargcr
Copy link
Author

knargcr commented Sep 4, 2024

This issue has been discussed on Discord as well, but unfortunately no solutions have been found yet. You can check out the conversation in the thread below:
https://discord.com/channels/603595811204366337/606457523574407178/1260165032566722610

@PixsaOJ
Copy link

PixsaOJ commented Sep 4, 2024

I just found solution. Might not be for everyone, or the final solution.

I applied this patch:

if (view !== null) {
  view.unmount();
  view = null;
}

to here:

in node_modules

I do not know if it works for you

@vallemar
Copy link
Contributor

@knargcr The root cause of this issue was related to this one #1091. It's fixed in version 3.0.0. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants