From 3c27d1ff7162fc60e9c2d517dec4628d034e8138 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Tue, 24 Jan 2023 12:50:03 -0500 Subject: [PATCH] [F] Fix initialization order --- app/src/main/java/org/hydev/wearsync/MyService.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/hydev/wearsync/MyService.kt b/app/src/main/java/org/hydev/wearsync/MyService.kt index 69b255e..ba9d388 100644 --- a/app/src/main/java/org/hydev/wearsync/MyService.kt +++ b/app/src/main/java/org/hydev/wearsync/MyService.kt @@ -18,6 +18,7 @@ import org.hydev.wearsync.bles.BluetoothHandler.Companion.ble import org.hydev.wearsync.bles.decoders.BatteryDecoder import org.hydev.wearsync.bles.decoders.HeartRateDecoder import org.hydev.wearsync.bles.decoders.IDecoder +import timber.log.Timber import java.util.concurrent.atomic.AtomicLong @@ -50,7 +51,7 @@ class MyService : Service() private fun add(it: Any) = scope.launch { runCatching { - println("Adding ${it.javaClass.simpleName} to influxdb") + Timber.d("Adding ${it.javaClass.simpleName} to influxdb") influx add it "Recorded ${count.addAndGet(1)} events!".notif() @@ -61,8 +62,8 @@ class MyService : Service() override fun onReceive(ctxt: Context, intent: Intent) { add(intent.batteryInfo(bm)) } } - private val intent = PendingIntent.getActivity(this, 0, intent(), - PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) + private val intent by lazy { PendingIntent.getActivity(this, 0, intent(), + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) } private fun String.notif() = startForeground(NOTIF_ID, NotificationCompat.Builder(this@MyService, NOTIF_CHANNEL_ID)