fix: 解绑时重置bindHandled标记 + 绑定加Toast调试

解绑后bindHandled没重置导致再次绑定时消息被跳过。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dongliang
2026-05-11 14:26:18 +09:30
parent 83894670d3
commit 6d8e73c8da

View File

@@ -140,6 +140,7 @@ class MainActivity : AppCompatActivity() {
android.widget.Toast.makeText(this@MainActivity, "收到解绑消息", android.widget.Toast.LENGTH_SHORT).show()
bluetoothScanManager.stop()
userPrefs.clear()
bindHandled = false // 重置绑定标记,允许重新绑定
try {
val navHost = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment
@@ -257,7 +258,11 @@ class MainActivity : AppCompatActivity() {
/** 处理 MQTT type=2 绑定消息Activity 级别,不受 Fragment 生命周期影响) */
private fun handleBindMessage(rawJson: String) {
if (bindHandled) return
android.widget.Toast.makeText(this, "收到绑定消息", android.widget.Toast.LENGTH_SHORT).show()
if (bindHandled) {
android.widget.Toast.makeText(this, "绑定已处理过,跳过", android.widget.Toast.LENGTH_SHORT).show()
return
}
bindHandled = true
try {