rekabhq / background_locator

A Flutter plugin for updating location in background.
MIT License
288 stars 329 forks source link

App crashes upon starting background locator #215

Open kelvinforteta opened 3 years ago

kelvinforteta commented 3 years ago

Good day, My app keeps crashing anytime I start the background locator -> Stops the background locator -> start the background locator -> crash.

I have this code that registers SQflite plugin

if (!registry!!.hasPlugin("com.tekartik.sqflite")) {
            SqflitePlugin.registerWith(registry!!.registrarFor("com.tekartik.sqflite.SqflitePlugin"))
        }

I think the crash is caused by SQflite because anytime it crashes I get this error message _"Unable to create service rekab.app.backgroundlocator.IsolateHolderService: java.lang.IllegalStateException: Plugin key com.tekartik.sqflite.SqflitePlugin is already in use"

Is there a way to prevent SQflite from running more than once when I try to start the background service?

Below is the error from the terminal:

D/BackgroundLocatorPlugin(13239): start locator with Google client
D/AndroidRuntime(13239): Shutting down VM
E/AndroidRuntime(13239): FATAL EXCEPTION: main
E/AndroidRuntime(13239): Process: com.bulwarkpublishing.thermal, PID: 13239
E/AndroidRuntime(13239): java.lang.RuntimeException: Unable to create service rekab.app.background_locator.IsolateHolderService: java.lang.IllegalStateException: Plugin key com.tekartik.sqflite.SqflitePlugin is already in use
E/AndroidRuntime(13239):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3965)
E/AndroidRuntime(13239):    at android.app.ActivityThread.access$1500(ActivityThread.java:219)
E/AndroidRuntime(13239):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
E/AndroidRuntime(13239):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(13239):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(13239):    at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(13239):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(13239):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(13239):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime(13239): Caused by: java.lang.IllegalStateException: Plugin key com.tekartik.sqflite.SqflitePlugin is already in use
E/AndroidRuntime(13239):    at io.flutter.app.FlutterPluginRegistry.registrarFor(FlutterPluginRegistry.java:75)
E/AndroidRuntime(13239):    at com.bulwarkpublishing.thermal.Application.registerWith(Application.kt:26)
E/AndroidRuntime(13239):    at rekab.app.background_locator.IsolateHolderExtensionKt.startLocatorService(IsolateHolderExtension.kt:36)
E/AndroidRuntime(13239):    at rekab.app.background_locator.IsolateHolderService.onCreate(IsolateHolderService.kt:115)
E/AndroidRuntime(13239):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3953)
E/AndroidRuntime(13239):    ... 8 more
I/Process (13239): Sending signal. PID: 13239 SIG: 9
JeanRoldanDev commented 3 years ago
    override fun registerWith(registry: PluginRegistry?) {
        if (!registry!!.hasPlugin("com.tekartik.sqflite.SqflitePlugin")) {
            SqflitePlugin.registerWith(registry!!.registrarFor("com.tekartik.sqflite.SqflitePlugin"))
        }
    }

it is solution :3

kelvinforteta commented 3 years ago

Thank you so much, It worked.

s15-coder commented 3 years ago

@jeancarlos2020 I have some question. I'm already using an Application file in my android project to use a Firebase integration, it file is in Java. There is some place where can see how register the different plugins with Java? I clarify that I have more than one plugin to use in the background location callback

I would appreciate your help please

JeanRoldanDev commented 3 years ago

@ jeancarlos2020 Tengo una pregunta. Ya estoy usando un archivo de aplicación en mi proyecto de Android para usar una integración de Firebase, su archivo está en Java. ¿Hay algún lugar donde pueda ver cómo registrar los diferentes complementos con Java? Aclaro que tengo más de un complemento para usar en la devolución de llamada de ubicación en segundo plano

Agradeceria tu ayuda por favor

You need to check the manufacturer name in the android or ios folder of each added package, these are the ones I use now and it works perfectly

      if (!registry!!.hasPlugin("io.flutter.plugins.firebase.database")) {
            FirebaseDatabasePlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebase.database"))
        }
        if (!registry!!.hasPlugin("io.flutter.plugins.androidalarmmanager")) {
            AndroidAlarmManagerPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.androidalarmmanager"))
        }
        if (!registry!!.hasPlugin("com.dexterous.flutterlocalnotifications")) {
            FlutterLocalNotificationsPlugin.registerWith(registry!!.registrarFor("com.dexterous.flutterlocalnotifications"))
        }
        if (!registry!!.hasPlugin("io.flutter.plugins.firebasemessaging")) {
            FirebaseMessagingPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebasemessaging"))
        }
        if (!registry!!.hasPlugin("com.tekartik.sqflite.SqflitePlugin")) {
            SqflitePlugin.registerWith(registry!!.registrarFor("com.tekartik.sqflite.SqflitePlugin"))
        }
JeanRoldanDev commented 3 years ago

Muchas gracias, funcionó. Good..! @mehdok closing the issue.