简体   繁体   English

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

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

`I have written this code for loading screen of my android app. `我已经为我的 android 应用程序的加载屏幕编写了这段代码。 But whenever i install it on my phone the fps of my loading screen is very low seems like it has 2-3 fps The loading screen is a gif file.但是每当我将它安装在我的手机上时,我的加载屏幕的 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()
    }
}
    

` `

You can use coroutine instead of regular thread.您可以使用协程而不是常规线程。

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

Dont forget to add coroutines to your dependencies in your app's build.gradle不要忘记将协程添加到应用程序的依赖项中 build.gradle

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

You can read more about them here: https://reflectoring.io/understanding-kotlin-coroutines-tutorial/#:~:text=Coroutines%20are%20more%20efficient%20than,for%20the%20coroutines%20to%20complete .你可以在这里阅读更多关于它们的信息: 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.

相关问题 我的应用程序加载时如何避免Android中的黑屏? - How to avoid black screen in android while my app is loading? Android应用程序登录屏幕未加载 - Android app login screen not loading Android App卡在了加载屏幕中-Android Studio - Android App is stuck in a loading screen - Android Studio 流星:Cordova Android应用程序停留在加载屏幕上 - Meteor: Cordova Android app stuck on loading screen 应用程序卡在 android 模拟器的加载屏幕上 - App is stuck on loading screen on android emulator 在Android应用程序中加载资源时启动屏幕 - Splash screen while loading resources in android app Android应用在设备上加载白屏 - Android app loading white screen on device 捕获屏幕Android,但不是我的App - Capture Screen Android, but not my App 当我返回之前打开的应用程序时,如何禁用android的屏幕状态自动保存和加载功能? - How to disable the automatic saving and loading of the screen state by android when I return to my previously opened app? 在我的Android应用程序中从前置摄像头录制时,无法获得高fps(每秒帧数)速率(约30fps) - Unable to get high fps(frames per second) rate(around 30fps) while recording from front camera in my Android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM