question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suspending or minimizing my app messes UI and crashes app

See original GitHub issue

Hi. I have this little problem with my NativeScript app. I just created a new project using the Hello World template. And I noticed that the app’s UI disappears when app issuspended once, and crashes when it gets suspended or minimized twice.

The following text appear in my command line on Windows:

W/System.err(29479): com.tns.Runtime.callJSMethodNative(Native Method) W/System.err(29479): com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043) W/System.err(29479): com.tns.Runtime.callJSMethodImpl(Runtime.java:925) W/System.err(29479): com.tns.Runtime.callJSMethod(Runtime.java:912) W/System.err(29479): com.tns.Runtime.callJSMethod(Runtime.java:896) W/System.err(29479): com.tns.Runtime.callJSMethod(Runtime.java:888) W/System.err(29479): at com.tns.Runtime.callJSMethodNative(Native Method) W/System.err(29479): at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043) W/System.err(29479): at com.tns.Runtime.callJSMethodImpl(Runtime.java:925) W/System.err(29479): at com.tns.Runtime.callJSMethod(Runtime.java:912) W/System.err(29479): at com.tns.Runtime.callJSMethod(Runtime.java:896) W/System.err(29479): at com.tns.Runtime.callJSMethod(Runtime.java:888) W/System.err(29479): com.tns.Runtime.callJSMethodNative(Native Method) W/System.err(29479): com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043) W/System.err(29479): com.tns.Runtime.callJSMethodImpl(Runtime.java:925) W/System.err(29479): com.tns.Runtime.callJSMethod(Runtime.java:912) W/System.err(29479): com.tns.Runtime.callJSMethod(Runtime.java:896) W/System.err(29479): com.tns.Runtime.callJSMethod(Runtime.java:888) W/System.err(29479): at com.tns.Runtime.callJSMethodNative(Native Method) W/System.err(29479): at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043) W/System.err(29479): at com.tns.Runtime.callJSMethodImpl(Runtime.java:925) W/System.err(29479): at com.tns.Runtime.callJSMethod(Runtime.java:912) W/System.err(29479): at com.tns.Runtime.callJSMethod(Runtime.java:896) W/System.err(29479): at com.tns.Runtime.callJSMethod(Runtime.java:888)

The exception report states the following:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to resume activity {org.nativescript.SCI/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
Calling js method onStart failed

Error: java.lang.NullPointerException
    android.view.ViewGroup.removeViewInternal(ViewGroup.java:4041)
    android.view.ViewGroup.removeViewAt(ViewGroup.java:3998)
    org.nativescript.widgets.GridLayout.removeViewAt(GridLayout.java:143)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
    com.tns.Runtime.callJSMethod(Runtime.java:912)
    com.tns.Runtime.callJSMethod(Runtime.java:896)
    com.tns.Runtime.callJSMethod(Runtime.java:888)
    com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
    android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174)
    android.app.Activity.performStart(Activity.java:5274)
    android.app.Activity.performRestart(Activity.java:5330)
    android.app.Activity.performResume(Activity.java:5335)
    android.app.ActivityThread.performResumeActivity(ActivityThread.java:2950)
    android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2993)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
    android.os.Handler.dispatchMessage(Handler.java:110)
    android.os.Looper.loop(Looper.java:193)
    android.app.ActivityThread.main(ActivityThread.java:5292)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:515)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
    dalvik.system.NativeStart.main(Native Method)
File: "file:///data/data/org.nativescript.SCI/files/app/main-page.js, line: 17, column: 50

StackTrace:
Frame: function:'initialDelaration', file:'file:///data/data/org.nativescript.SCI/files/app/main-page.js', line: 17, column: 51
Frame: function:'Observable.notify', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
Frame: function:'Observable._emit', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 120, column: 18
Frame: function:'ViewBase.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 208, column: 14
Frame: function:'View.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 62, column: 35
Frame: function:'PageBase.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/page/page-common.js', line: 91, column: 35
Frame: function:'Page.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/page/page.js', line: 105, column: 35
Frame: function:'', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 212, column: 19
Frame: function:'FrameBase.eachChildView', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 350, column: 13
Frame: function:'ViewCommon.eachChild', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 690, column: 14
Frame: function:'ViewBase._loadEachChild', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 211, column: 14
Frame: function:'ViewBase.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 207, column: 14
Frame: function:'View.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 62, column: 35
Frame: function:'ActivityCallbacksImplementation.onStart', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 724, column: 22
Frame: function:'NativeScriptActivity.onStart', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 26, column: 25

at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2993)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: com.tns.NativeScriptException:
Calling js method onStart failed

Error: java.lang.NullPointerException
    android.view.ViewGroup.removeViewInternal(ViewGroup.java:4041)
    android.view.ViewGroup.removeViewAt(ViewGroup.java:3998)
    org.nativescript.widgets.GridLayout.removeViewAt(GridLayout.java:143)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
    com.tns.Runtime.callJSMethod(Runtime.java:912)
    com.tns.Runtime.callJSMethod(Runtime.java:896)
    com.tns.Runtime.callJSMethod(Runtime.java:888)
    com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
    android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174)
    android.app.Activity.performStart(Activity.java:5274)
    android.app.Activity.performRestart(Activity.java:5330)
    android.app.Activity.performResume(Activity.java:5335)
    android.app.ActivityThread.performResumeActivity(ActivityThread.java:2950)
    android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2993)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
    android.os.Handler.dispatchMessage(Handler.java:110)
    android.os.Looper.loop(Looper.java:193)
    android.app.ActivityThread.main(ActivityThread.java:5292)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:515)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
    dalvik.system.NativeStart.main(Native Method)
File: "file:///data/data/org.nativescript.SCI/files/app/main-page.js, line: 17, column: 50

StackTrace:
Frame: function:'initialDelaration', file:'file:///data/data/org.nativescript.SCI/files/app/main-page.js', line: 17, column: 51
Frame: function:'Observable.notify', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
Frame: function:'Observable._emit', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 120, column: 18
Frame: function:'ViewBase.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 208, column: 14
Frame: function:'View.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 62, column: 35
Frame: function:'PageBase.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/page/page-common.js', line: 91, column: 35
Frame: function:'Page.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/page/page.js', line: 105, column: 35
Frame: function:'', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 212, column: 19
Frame: function:'FrameBase.eachChildView', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 350, column: 13
Frame: function:'ViewCommon.eachChild', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 690, column: 14
Frame: function:'ViewBase._loadEachChild', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 211, column: 14
Frame: function:'ViewBase.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 207, column: 14
Frame: function:'View.onLoaded', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 62, column: 35
Frame: function:'ActivityCallbacksImplementation.onStart', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 724, column: 22
Frame: function:'NativeScriptActivity.onStart', file:'file:///data/data/org.nativescript.SCI/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 26, column: 25

at com.tns.Runtime.callJSMethodNative(Native Method)
at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
at com.tns.Runtime.callJSMethod(Runtime.java:912)
at com.tns.Runtime.callJSMethod(Runtime.java:896)
at com.tns.Runtime.callJSMethod(Runtime.java:888)
at com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174)
at android.app.Activity.performStart(Activity.java:5274)
at android.app.Activity.performRestart(Activity.java:5330)
at android.app.Activity.performResume(Activity.java:5335)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2950)
... 10 more
Caused by: java.lang.NullPointerException
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4041)
at android.view.ViewGroup.removeViewAt(ViewGroup.java:3998)
at org.nativescript.widgets.GridLayout.removeViewAt(GridLayout.java:143)
... 22 more

and the logcat is attached. logcat.txt

The issue is simple to trigger: Just minimize or suspend twice. The first time, the UI will disappear. The second time, the app will crash.

If you need my project to test the issue here it is.

https://goo.gl/MqKGYD

I’m using a 4.4.2 tablet to test the app, as that is the minimum target.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JorgeHawkinscommented, Aug 10, 2017

I found that the device constantly tries to free resources as soon as the app gets suspended or minimized, as the table has only about 300 MB of RAM. I used the LowMemory event to detect the issue. As soon as I added it to my code, every single time I suspended the application, the app would throw a low memory warning. I added an exception to the LowMemory event and “solved” it.

0reactions
lock[bot]commented, Aug 28, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Stop Apps From Crashing on Android - AVG
Freezing apps can be caused by the apps themselves, due to programming bugs, or by the way they're used — if you try...
Read more >
Fix suspended app crashing - Microsoft Community
To check the app reset it in Settings > Apps > Apps & Features > App Name > Advanced Options.
Read more >
Apps Crashing! Here's The Simple Fix - YouTube
Reserve & Learn about the upcoming Galaxy Z Fold4, Z Flip4, Galaxy Watch 5 & Galaxy Buds Here: https://howl.me/chG8oceCDPIWelcome to the ...
Read more >
How to Stop an App From Constantly Crashing | #XiaomiSupport
No!!! The same App just keeps on crashing ! Don't get frustrated, watch this instead. #XiaomiSupportLearn More:https://www.mi.com/global/ ...
Read more >
Crashing, freezing, or unexpectedly restarting troubleshooting
Crashing, freezing, and restarting are usually signs of a software or app problem. This means your device isn't broken, but probably needs some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found