1.问题在执行听写业务逻辑时候,执行了回到播放声音,但是clearTask 又置回原始状态,声音播放被打断
runBusiness(){
...
...
onResultSpeechCallBackListener(mContent);//回调
clearTask();//
}
clearTask(){
mHandler2.obtainMessage(2).sendToTarget();}
public void onTest(View view) {
Log.i("zdy", "what=.......1");
mHandler.obtainMessage(1).sendToTarget();
Log.i("zdy", "what=.......2");
mHandler.obtainMessage(2).sendToTarget();
Log.i("zdy", "what=.......3");
Log.e("zdy", "what=.......1");
mHandler2.obtainMessage(1).sendToTarget();
Log.e("zdy", "what=.......2");
mHandler2.obtainMessage(2).sendToTarget();
Log.e("zdy", "what=.......3");
}
先执行完log的打印才开始执行mHandler内的逻辑
2.线程中使用handler 需要
Looper.prepare();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
responeStartWithIF();// 铃声已经想起然后断开蓝牙
}
}, 2000);
Looper.loop();
3.@Override 一个线程中只需要一次Looper.prepare(); ,否则出现only one Looper may be created per thread
public void startUpConnection(final IClientSession mClientSession) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
new Thread() {
public void run() {
try {
client = device
.createRfcommSocketToServiceRecord(UUID
.fromString("00001101-0000-1000-8000-00805F9B34FB"));
Looper.prepare();
LoadDialog.show(mContext, getLoginTip(), false);
client.connect();
Looper.loop();
Looper.prepare();
LoadDialog.dismiss(mContext);
Looper.loop();
mClientSession.registerSession();
SocketClientSessionMnager.getInstance().addToList(
mClientSession);
mClientSession.onLogin();
} catch (IOException e) {
// TODO Auto-generated catch block
LoadDialog.dismiss(mContext);
LoadDialog.show(mContext, getLoginFaileTip(), false);
Looper.loop();
e.printStackTrace();
}
}
}.start();
}