How can I Toast after Text to Speech finish speak. Actually I want to do someting more than Log. This is my code.
public class MainActivity extends AppCompat
You try to show a Toast
in a thread that is not the UI(main) thread.
You should change this
@Override
public void onUtteranceCompleted(String utteranceId) {
Log.i("CALLBACK", utteranceId); //utteranceId == "SOME MESSAGE"
Toast.makeText(getApplicationContext(),"Call Back",Toast.LENGTH_LONG).show();// I Cannot Toast here. Or do something more than Log
}
into this
@Override
public void onUtteranceCompleted(String utteranceId) {
Log.i("CALLBACK", utteranceId); //utteranceId == "SOME MESSAGE"
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(),"Call Back",Toast.LENGTH_LONG).show();
}
});
}
That way your code is dispatched to the main thread where you are allowed to show Toast
s