0

I'm trying to do a Handler (). PostDelayed in kotlin using java as the base, however this time I get an error, could someone answer why this happens? And what would be the most up-to-date solution? And for what reason are there functions or classes that appear crossed out, as in this case Handler ()?:

Handler().postDelayed(Runnable {

            override fun run()
            {
                val sharedPreferences = getSharedPreferences("SharedPref", MODE_PRIVATE)
                var isFirstTime : Boolean = sharedPreferences.getBoolean("firstTime", true)
            }
        }, SPLASH_TIME_OUT.toLong())

enter image description here

Zain
  • 37,492
  • 7
  • 60
  • 84
Pxnditx YR
  • 79
  • 1
  • 10
  • refer to this answer: https://stackoverflow.com/questions/63517194/how-to-handle-deprecated-handler-in-android/63517606#63517606 – Alpha 1 Nov 07 '20 at 02:48

1 Answers1

1

Take advantage of lambda in Kotlin. below code will work:

Handler(Looper.getMainLooper()).postDelayed({
                val sharedPreferences = getSharedPreferences("SharedPref", MODE_PRIVATE)
                var isFirstTime : Boolean = sharedPreferences.getBoolean("firstTime", true)
        }, SPLASH_TIME_OUT.toLong())

Also refer to my answer here: How to handle deprecated Handler in android

Alpha 1
  • 4,118
  • 2
  • 17
  • 23