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);
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.
Go to the User. java file and convert it to Kotlin: Menu bar -> Code -> Convert Java File to Kotlin File.
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 .
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.
Handler(Looper.getMainLooper()).postDelayed({
/* Create an Intent that will start the Menu-Activity. */
val mainIntent = Intent(this, Menu::class.java)
startActivity(mainIntent)
finish()
}, 3000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With