Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert java to kotlin in handler

how to Convert java to kotlin in handler

new Handler().postDelayed(new Runnable(){
    @Override
    public void run() {
        /* Create an Intent that will start the Menu-Activity. */
        Intent mainIntent = new Intent(Splash.this,Menu.class);
        Splash.this.startActivity(mainIntent);
        Splash.this.finish();
    }
}, 3000);
like image 676
Prabhakaran P Avatar asked Jun 10 '17 11:06

Prabhakaran P


People also ask

Can you convert Java to Kotlin?

Once Android Studio finished the build of project files, open the created Kotlin Class/File. Copy the Java code which is to be converted. Paste that code in the created file/class having Kotlin extension. That Java code will get converted automatically into Kotlin by the Android Studio.

How do I transfer Java code to Kotlin?

Go to the User. java file and convert it to Kotlin: Menu bar -> Code -> Convert Java File to Kotlin File.

How do you make a Kotlin handler?

1. Run handler in main thread. Looper includes a helper function, getMainLooper() , which retrieves the Looper of the main thread. You can run code in the main thread by using this Looper to create a Handler .

How do you use Kotlin handler postDelayed?

The postDelayed method takes two parameters Runnable and delayMillis . It adds the Runnable to the thread's message queue to be run after the specified amount of time elapses. The Runnable will execute on the thread to which this handler is attached.


1 Answers

Handler(Looper.getMainLooper()).postDelayed({
    /* Create an Intent that will start the Menu-Activity. */
    val mainIntent = Intent(this, Menu::class.java)
    startActivity(mainIntent)
    finish()
}, 3000)
like image 117
RobCo Avatar answered Sep 19 '22 11:09

RobCo