【问题标题】:How to Convert java to kotlin in handler如何在处理程序中将 java 转换为 kotlin
【发布时间】:2017-11-12 08:31:49
【问题描述】:

如何在处理程序中将 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);

【问题讨论】:

  • 您可以使用Code-> Convert Java File to Kotlin File 作为开始。您也可以将此代码粘贴到 Kotlin 文件中,它会为您转换。

标签: java android xml kotlin


【解决方案1】:
Handler(Looper.getMainLooper()).postDelayed({
    /* Create an Intent that will start the Menu-Activity. */
    val mainIntent = Intent(this, Menu::class.java)
    startActivity(mainIntent)
    finish()
}, 3000)

【讨论】:

  • @creativecoder 默认构造函数已弃用。它现在指定主循环器以避免此问题并确保延迟的代码始终在主线程上运行。
猜你喜欢
  • 2019-03-12
  • 1970-01-01
  • 2022-01-07
  • 2018-11-26
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
相关资源
最近更新 更多