Explorar o código

Changed to async exe in global scope for db-insert

Thomas Chef %!s(int64=3) %!d(string=hai) anos
pai
achega
11e14a9438

+ 6 - 6
app/src/main/java/com/flacksta/chef/journeygpstracker/TrackingService.kt

@@ -17,6 +17,8 @@ import androidx.core.content.ContextCompat
 import com.flacksta.chef.journeygpstracker.database.GpsData
 import com.flacksta.chef.journeygpstracker.database.GpsPosRepository
 import com.google.android.gms.location.*
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.runBlocking
 
@@ -40,12 +42,10 @@ class TrackingService : Service() {
         Log.i(mTag,"Requested foreground service...")
     }
 
-    private fun insertPos(pos: Location) = runBlocking {
-        launch {
-            var d = GpsData(0, System.currentTimeMillis(), pos.latitude, pos.longitude, pos.accuracy)
-            val repo: GpsPosRepository = trackApp.repository
-            repo.insert(d)
-        }
+    private fun insertPos(pos: Location) = GlobalScope.launch {
+        var d = GpsData(0, System.currentTimeMillis(), pos.latitude, pos.longitude, pos.accuracy)
+        val repo: GpsPosRepository = trackApp.repository
+        repo.insert(d)
     }
 
     private fun requestLocationUpdates() {