Resolve too many Widget threads

This commit is contained in:
Milos Kozak 2022-09-29 13:49:19 +02:00
parent ea156511e0
commit 1c94a20a5c

View file

@ -54,7 +54,11 @@ class Widget : AppWidgetProvider() {
@Inject lateinit var sp: SP
@Inject lateinit var constraintChecker: ConstraintChecker
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
companion object {
// This object doesn't behave like singleton,
// many threads were created. Making handler static resolve this issue
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
}
private val intentAction = "OpenApp"
override fun onReceive(context: Context, intent: Intent?) {