Android Handler callback not removed for token type Int or Long (*Kotlin)

戏子无情 提交于 2020-06-23 05:14:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!