体验优化: 拆除Splash屏2秒线程硬等待,改为异步检查就绪状态
This commit is contained in:
parent
58885f69a9
commit
7060b99dd9
|
|
@ -7,14 +7,37 @@ import android.os.Looper
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
|
||||||
class SplashActivity : AppCompatActivity() {
|
class SplashActivity : AppCompatActivity() {
|
||||||
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
private var checkCount = 0
|
||||||
|
private val maxChecks = 20 // 最多检查20次(2秒)
|
||||||
|
|
||||||
|
private val checkInitRunnable = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
if (MyApplication.pNative != null || checkCount >= maxChecks) {
|
||||||
|
navigateToLogin()
|
||||||
|
} else {
|
||||||
|
checkCount++
|
||||||
|
handler.postDelayed(this, 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_splash)
|
setContentView(R.layout.activity_splash)
|
||||||
|
|
||||||
// 延迟 2 秒进入登录界面
|
// 异步检查PTT JNI初始化状态,避免硬等待2秒
|
||||||
Handler(Looper.getMainLooper()).postDelayed({
|
handler.post(checkInitRunnable)
|
||||||
startActivity(Intent(this, LoginActivity::class.java))
|
}
|
||||||
finish()
|
|
||||||
}, 2000)
|
private fun navigateToLogin() {
|
||||||
|
if (isFinishing || isDestroyed) return
|
||||||
|
startActivity(Intent(this, LoginActivity::class.java))
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
handler.removeCallbacks(checkInitRunnable)
|
||||||
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue