Android - Background notification causing app to crash after upgrade to 5.1.1
See original GitHub issueHi,
I upgraded to the 5.1.1 of the plugin recently and am running tns 3.4 Notifications are received perfectly in the foreground.
However when running the app in the background on Android the notification is received in the phones notification panel. On clicking this background notification, the app crashes with the following error.
An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.qbank/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
Calling js method onCreate failed
Error: com.google.firebase.database.DatabaseException: Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance.
com.google.firebase.database.FirebaseDatabase.zzph(Unknown Source:41)
com.google.firebase.database.FirebaseDatabase.setPersistenceEnabled(Unknown Source:3)
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
com.tns.Runtime.callJSMethod(Runtime.java:957)
com.tns.Runtime.callJSMethod(Runtime.java:941)
com.tns.Runtime.callJSMethod(Runtime.java:933)
com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:13)
android.app.Activity.performCreate(Activity.java:6998)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
android.app.ActivityThread.-wrap11(Unknown Source:0)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
android.os.Handler.dispatchMessage(Handler.java:105)
android.os.Looper.loop(Looper.java:164)
android.app.ActivityThread.main(ActivityThread.java:6809)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
File: "file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-plugin-firebase/firebase.js, line: 189, column: 44
StackTrace:
Frame: function:'runInit', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-plugin-firebase/firebase.js', line: 189, column: 45
Frame: function:'Observable.notify', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
Frame: function:'ActivityCallbacksImplementation.notifyLaunch', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 621, column: 21
Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 585, column: 29
Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: com.tns.NativeScriptException:
Calling js method onCreate failed
Error: com.google.firebase.database.DatabaseException: Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance.
com.google.firebase.database.FirebaseDatabase.zzph(Unknown Source:41)
com.google.firebase.database.FirebaseDatabase.setPersistenceEnabled(Unknown Source:3)
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
com.tns.Runtime.callJSMethod(Runtime.java:957)
com.tns.Runtime.callJSMethod(Runtime.java:941)
com.tns.Runtime.callJSMethod(Runtime.java:933)
com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:13)
android.app.Activity.performCreate(Activity.java:6998)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
android.app.ActivityThread.-wrap11(Unknown Source:0)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
android.os.Handler.dispatchMessage(Handler.java:105)
android.os.Looper.loop(Looper.java:164)
android.app.ActivityThread.main(ActivityThread.java:6809)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
File: "file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-plugin-firebase/firebase.js, line: 189, column: 44
StackTrace:
Frame: function:'runInit', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-plugin-firebase/firebase.js', line: 189, column: 45
Frame: function:'Observable.notify', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
Frame: function:'ActivityCallbacksImplementation.notifyLaunch', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 621, column: 21
Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 585, column: 29
Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.qbank/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
at com.tns.Runtime.callJSMethodNative(Native Method)
at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
at com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
at com.tns.Runtime.callJSMethod(Runtime.java:957)
at com.tns.Runtime.callJSMethod(Runtime.java:941)
at com.tns.Runtime.callJSMethod(Runtime.java:933)
at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6998)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
... 9 more
Caused by: com.google.firebase.database.DatabaseException: Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance.
at com.google.firebase.database.FirebaseDatabase.zzph(Unknown Source:41)
at com.google.firebase.database.FirebaseDatabase.setPersistenceEnabled(Unknown Source:3)
... 19 more
Please suggest what I can do to fix this issue.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Crash when app is moved into background on Samsung ...
In our case it has created issues with DocumentSaverService, which we use in Krita to save the document when the app goes in...
Read more >Fix Android Apps Keep Crashing OR App Keeps Stopping ...
If your Android apps keep crashing or keeps closing here is how to fix your phone. Do you get the following message when...
Read more >Fix an installed Android app that isn't working - Google Support
Try the following steps if an app installed on your phone has any of these problems: Crashing. Won't open. Won't respond. Isn't working...
Read more >App launch is crashing on app launch with Android 5.1.1 ...
We noticed that our app is crashing after the last curly bracket "}" in OnCreate method. It is launching an exception without prior...
Read more >Crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I hope 5.1.2 will help in this respect.
Hi @EddyVerbruggen ,
You are correct. That’s what seems to be happening. I tried to prevent firebase.init from happening again as below, but that didn’t work for me. Is there any other way to check and prevent init from calling a second time?
if (firebase.ServerValue !== undefined) { console.log("Firebase already there"); } else{ firebase.init({.......