Trying to call Toaster or Custom function inside setOnUtteranceProgressListener

泄露秘密 提交于 2019-12-06 04:58:13
naxrohan

ok I got a solution, now my question just seems trivial

my updated code looks like this:

@Override
public void onDone(String utteranceId) {

runOnUiThread(new Runnable() {

                public void run() {
                    Toast.makeText(getContext(),utteranceId,Toast.LENGTH_LONG).show();
gotoNextChapter(); <====function I want to call
read_mode = 0;
                }
            });
}

Thanks to these guyes here: How can I Toast after Text to Speech finish speaking Android and When may we need to use runOnUiThread in android application?

If you are in Activity:

runOnUiThread(new Runnable() {
    @Override
    public void run() { 
        Toast.makeText(getActivity(),"...", Toast.LENGTH_LONG).show();  
    }
});

If you are in a fragment:

getActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {
        Toast.makeText(getActivity(),"...", Toast.LENGTH_LONG).show();         
    }
});

Else you can do this:

Handler mainHandler = new Handler(context.getMainLooper());

Runnable myRunnable = new Runnable() {
    @Override 
    public void run() {
        Toast.makeText(getActivity(),"...", Toast.LENGTH_LONG).show();  
    } 
};
mainHandler.post(myRunnable);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!