SpeechRecognizer : not connected to recognition service

五迷三道 提交于 2019-12-04 07:57:58

I found the reason to the problem. In onPause method though SpeechRecognition.destroy() method is called, I guess it just detaches the service but the object sr will be pointing to some instance and it wont be null. Resetting the object sr to null would solve the problem.

Not destroying the SpeechRecognition object in onPause method would block other apps from using SpeechRecognition service

@Override
protected void onPause() {

    Log.i(CLASS_TAG, "on pause called");
    if(sr!=null){
        sr.stopListening();
        sr.cancel();
        sr.destroy();              

    }
    sr = null;

    super.onPause();
}

Just stop calling stopListening() and cancel() methods. Instead call destroy() methods only. this should fix the problem :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!