fix: 解绑时重置bindHandled标记 + 绑定加Toast调试
解绑后bindHandled没重置导致再次绑定时消息被跳过。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -140,6 +140,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
android.widget.Toast.makeText(this@MainActivity, "收到解绑消息", android.widget.Toast.LENGTH_SHORT).show()
|
android.widget.Toast.makeText(this@MainActivity, "收到解绑消息", android.widget.Toast.LENGTH_SHORT).show()
|
||||||
bluetoothScanManager.stop()
|
bluetoothScanManager.stop()
|
||||||
userPrefs.clear()
|
userPrefs.clear()
|
||||||
|
bindHandled = false // 重置绑定标记,允许重新绑定
|
||||||
try {
|
try {
|
||||||
val navHost = supportFragmentManager
|
val navHost = supportFragmentManager
|
||||||
.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment
|
.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment
|
||||||
@@ -257,7 +258,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
/** 处理 MQTT type=2 绑定消息(Activity 级别,不受 Fragment 生命周期影响) */
|
/** 处理 MQTT type=2 绑定消息(Activity 级别,不受 Fragment 生命周期影响) */
|
||||||
private fun handleBindMessage(rawJson: String) {
|
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
|
bindHandled = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user