refactor(app): 优化 ReadCardActivity 中的时间延迟处理
- 使用 handler.postDelayed 替代 Thread.sleep 方法,提高 UI 响应性 - 在停止交易成功后添加延迟完成逻辑,提升用户体验 - 优化蓝牙设备断开连接和资源释放流程
This commit is contained in:
@@ -119,12 +119,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
public void connected() {
|
public void connected() {
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
Log.d(TAG, "connected1==========");
|
Log.d(TAG, "connected1==========");
|
||||||
try {
|
handler.postDelayed(ReadCardActivity.this::beginReadCard,1000);
|
||||||
Thread.sleep(200);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
beginReadCard();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -597,7 +592,7 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onStopTradeSuccess() {
|
public void onStopTradeSuccess() {
|
||||||
Log.e(TAG, "onStopTradeSuccess");
|
Log.e(TAG, "onStopTradeSuccess");
|
||||||
finish();
|
handler.postDelayed(ReadCardActivity.this::finish,1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -644,8 +639,11 @@ public class ReadCardActivity extends AppCompatActivity {
|
|||||||
if (mBluetoothController != null) {
|
if (mBluetoothController != null) {
|
||||||
Log.d(TAG,"释放mBluetoothController====");
|
Log.d(TAG,"释放mBluetoothController====");
|
||||||
mBluetoothController.scanLeDevice(false);
|
mBluetoothController.scanLeDevice(false);
|
||||||
|
mBluetoothController.disConnect();
|
||||||
mBluetoothController.close();
|
mBluetoothController.close();
|
||||||
|
// mBluetoothController.unRegisterConnectReceiver( this);
|
||||||
mBluetoothController.unRegisterReceiver();
|
mBluetoothController.unRegisterReceiver();
|
||||||
|
// mBluetoothController.release();
|
||||||
mBluetoothController = null;
|
mBluetoothController = null;
|
||||||
}
|
}
|
||||||
if (executorService != null && !executorService.isShutdown()) {
|
if (executorService != null && !executorService.isShutdown()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user