gpt4 book ai didi

java - 如何在处理程序中将 java 转换为 kotlin

转载 作者:IT老高 更新时间:2023-10-28 13:40:59 24 4
gpt4 key购买 nike

如何在处理程序中将 java 转换为 kotlin

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);

最佳答案

Java 转换为 Kotlin:

Handler(Looper.getMainLooper()).postDelayed({
val mainIntent = Intent(this, Menu::class.java)
startActivity(mainIntent)
finish()
}, 3000)

如果您使用的是 androidx-core-ktx 包,则有一个 extension function它将参数重新排序以更适合 Kotlin:

Handler(Looper.getMainLooper()).postDelayed(1000) {
// Do something
}

关于java - 如何在处理程序中将 java 转换为 kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44472765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com