繁体   English   中英

我的 android 应用程序加载屏幕中的 fps 更少

[英]Less fps in loading screen of my android app

`我已经为我的 android 应用程序的加载屏幕编写了这段代码。 但是每当我将它安装在我的手机上时,我的加载屏幕的 fps 非常低,似乎只有 2-3 fps 加载屏幕是一个 gif 文件。

class splash_screen:AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_screen)
        val gifImageView = findViewById<ImageView>(R.id.loading_gif)
        Glide.with(this).asGif().load(R.drawable.loading_gif).into(gifImageView)
        val background = object : Thread() {
            override fun run() {
                try {
                    Thread.sleep(5000)
                    val intent = Intent(baseContext, MainActivity::class.java)
                    startActivity(intent)
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
        }
        background.start()
    }
}
    

`

您可以使用协程而不是常规线程。

CoroutineScope(Dispatchers.IO).launch {
  delay(TimeUnit.SECONDS.toMillis(5))
  withContext(Dispatchers.Main) { startActivity(Intent(baseContext, MainActivity::class.java)) }
}

不要忘记将协程添加到应用程序的依赖项中 build.gradle

dependencies { 
 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
}

你可以在这里阅读更多关于它们的信息: https://reflectoring.io/understanding-kotlin-coroutines-tutorial/#:~:text=Coroutines%20are%20more%20efficient%20than,for%20the%20coroutines%20to%20complete

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM