diff --git a/app/src/main/java/com/stand/standapp/SplashActivity.kt b/app/src/main/java/com/stand/standapp/SplashActivity.kt index c63b1c4..ede5a3f 100644 --- a/app/src/main/java/com/stand/standapp/SplashActivity.kt +++ b/app/src/main/java/com/stand/standapp/SplashActivity.kt @@ -7,14 +7,37 @@ import android.os.Looper import androidx.appcompat.app.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?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash) - // 延迟 2 秒进入登录界面 - Handler(Looper.getMainLooper()).postDelayed({ - startActivity(Intent(this, LoginActivity::class.java)) - finish() - }, 2000) + // 异步检查PTT JNI初始化状态,避免硬等待2秒 + handler.post(checkInitRunnable) + } + + private fun navigateToLogin() { + if (isFinishing || isDestroyed) return + startActivity(Intent(this, LoginActivity::class.java)) + finish() + } + + override fun onDestroy() { + handler.removeCallbacks(checkInitRunnable) + super.onDestroy() } }