Handler

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();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值