Android SpeechRecognizer should only be used from the application's main thread

后端 未结 1 610
孤街浪徒
孤街浪徒 2021-01-21 20:33

I am trying to integrate some of Androids Speech APIS in my AndEngine based game.

I placed my code within the BaseGame activity - however this error appears at runtime:<

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 21:15

    Call the SpeechClass on the main thread by doing something like this:

    final SpeechClass c = getSpeechClass(); // get the speech class
    
    View v = findViewById(R.id.anyview); //fetch a View: any one will do
    
    v.post(new Runnable(){ public void run(){ c.doSomething(); }});
    

    That should run it on the main thread. Might slow your UI down if doSomething takes a while, but you get to work that out.

    0 讨论(0)
提交回复
热议问题