CPU load slowly creeping up while running coroutineScope launch periodically on Android with RoomDB update

14 Views Asked by At

In my Android application I have a simple case where I periodically poll for a new value and then run a RoomDB Query which updates the value in the database.

fun updateStatus(
    sensorId: String,
    state: String,
) {
    scope.launch {
        db.statusDao().setLastState(sensorId, state)
    }
}

... and ...

infoTimer = Timer()
    infoTimer.scheduleAtFixedRate(
        object : TimerTask() {
            override fun run() {
                ... in the end updateStatus() is called
            }
        },
        0,
        300,
    )

I noticed that while this is happening the CPU is constantly rising. Shorter the timeout the steeper it goes.

enter image description here

Any ideas what is causing this and how to stop it from happening?

0

There are 0 best solutions below