Hello, I have a problem when I use Kotlin in Andro...
# android
c
Hello, I have a problem when I use Kotlin in Android. I create a handler using
Copy code
kotlin
val handler: Handler = object : Handler() {
        override fun handleMessage(msg: Message) {
            when (msg.what) {
                0 -> { fab_next.show() }
            }
            super.handleMessage(msg)
        }
    }
and Android Studio told me
This Handler class should be static or leaks might occur
,but kotlin doesn't have
static
,So what should I do for this?
l
cubesky: You don't need to use the static keyword. In Kotlin, to get the same effect as a non static class, you use
inner class
. In your case, you have to use a non anonyous class and use a WeakReference
This delegate can help you for WeakReference: https://gist.github.com/LouisCAD/7ce3a30cb88c27858b12d5f26c118b0b
👍 1