Update GUI from Application Class

142 views Asked by At

I am trying to show logs on a overlay over all activities. I found this https://stackoverflow.com/a/19037235/3370924 answer which implements the overlay in the application class. I have added a TextView to the LinearLayout to show my logs.
At first it works but then I get the error android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
when I have opened a new Activity and I am trying to add a new string to the TextView.

Usually i use runOnUiThread() but this method is not available in Application class. Can anyone please help me?

1

There are 1 answers

0
CommonsWare On BEST ANSWER

If we pretend that your TextView is called tv, do:

tv.post(new Runnable() {
  @Override
  public void run() {
    // put your update-the-TextView code here
  }
});