0

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?

Community
  • 1
  • 1
lex
  • 77
  • 2
  • 9
  • Register your activities, in your Application class if you need this, It's bad practice but you should be able to access the view from the activity. – Mathijs Segers Jun 26 '15 at 11:58

1 Answers1

2

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
  }
});
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491