Android runonuithread () function fails

I am developing an application that uses a third-party tts called flite. I am doing something like the vehicle says a sentence. I want to highlight every word, as they say. To do this, I managed to get word-level callbacks from tts. the workflow is similar to this - the button "speak text" is pressed. It launches tt and then sends the text to flite tts, which is in C, and has been integrated with the application. Now, from the C code, after each word, I make two callbacks for two different java actions: one for serving tts, for speaking the word second for my test java activity for highlighting the word. I successfully receive word-level callbacks in my test activity, but after that I cannot execute any user interface.

Below is the code that I execute when I receive the callback: this is a function called from C code.

private void WordCallback(int isword) {// from // callback if (isword == -1) { Log.d(LOG_TAG, "its not a word"); } else if (isword == -2) { Log.d(LOG_TAG, "yeah..its the end"); } else { Log.d(LOG_TAG, "its word no " + isword); int word = isword; Log.d(LOG_TAG, "highlightwords"); highlightwords(isword); if (isword == 4) { Log.d(LOG_TAG, "in if"); new Thread(new Runnable() { @Override public void run() { Log.d(LOG_TAG, "thread started"); try { Flitetest.this.runOnUiThread(new Runnable() { @Override public void run() { Log.d(LOG_TAG, "run on ui"); textview.setText("#" + isword); } }); Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } }).start(); } } } 

FliteTest is the name of an activity. the log prints before "Thread started", but the code inside runonuithread () never executes, and there is no error either.

Also, if you write textview.settext("something") without thread and runonuithread (), it gives an error:

fatal signal 11(sigsegv) at 0x6fc64e87(code=1), thread 20292(SynthThread) .

What is the reason for this behavior?

+6
source share
1 answer

In Android ICS (4.0+) , if you have android:anyDensity=false in AndroidManifest.xml and you have forced to android:anyDensity=false GPU rendering on your ICS phone. This is also a problem for native Android apps. Your parameters should either not use the android:anyDensity=false parameters, or disable the forced display of a graphic on the phone. Since you cannot control the latter on other people's phones, the former seems to be the best solution. Remember to use the suffix ' dp ' for all your dimensions .

0
source

Source: https://habr.com/ru/post/948937/


All Articles