问题
I have this code executed in Kotlin
android project and it will log both messages. If I change the token
to Char
or String
it will print only one message which is the wanted behaviour. Same use-case in a java project in android works as it should.
val handler = Handler()
//val token1: Long = 1001L
//val token2: Int = 121
val token1: Long = 1001L
val token2: Int = 1002
handler.postAtTime(
{
Log.e("postAtTime 1", " printed 1 ")
handler.removeCallbacksAndMessages(token2)
},
token1,
SystemClock.uptimeMillis() + 2000
)
handler.postAtTime(
{
Log.e("postAtTime 2", " printed 2 ")
},
token2,
SystemClock.uptimeMillis() + 4000
)
My question is why in Kotlin for a token of type Int
, Long
the handler doesnt remove the callback?
EDIT If I try with commented values it works
来源:https://stackoverflow.com/questions/62405834/android-handler-callback-not-removed-for-token-type-int-or-long-kotlin