Schrodingdong / Eldycare

Health care & monitoring system for elderly
0 stars 0 forks source link

Fix number of couroutine execution #1

Closed Schrodingdong closed 10 months ago

Schrodingdong commented 10 months ago

Check why we have 2 or more executions in couroutines / launched effect tasks Example for login image it causes some bugs

Schrodingdong commented 10 months ago

The issue is that we have the LaunchedEffect without a key. similar to react, LaunchEffect executes once and on each recomposition. When we put null as a value in the key, the launch is made only once upon composition

// Start the reminders service
LaunchedEffect(key1 = null, block = {
    val serviceIntent = Intent(context, ReminderService::class.java)
    serviceIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
    context.startService(serviceIntent)
})

Note : this websocket logic should be changed from composition level, to a more sophisticated level (run thread upon login)