In Android using Java, when using a listener callback method that can be called from multiple threads according to the documentation, is there any harm in forcing it to run on the main thread by surrounding the method body with runOnUiThread
like this:
@Override
public void onSomeBackgroundTaskCameToAnEndDueToReasonNumber21(final int taskID) {
runOnUiThread(new Runnable() {
// put all code here
}
}
in order to prevent accidentally "touching views" from a background thread in subsequent chains of method calls?
When the Android developers choose to make one of these callback fire on a background thread, what is the reason?
An example of such a class is UtteranceProgressListener
used on TextToSpeech objects.