从应用程序更新 GUI Class

Update GUI from Application Class

我正在尝试在所有活动的覆盖层上显示日志。我找到了这个 答案,它在应用程序 class 中实现了覆盖。我已将 TextView 添加到 LinearLayout 以显示我的日志。
起初它可以工作,但后来我收到错误 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
当我打开一个新的 Activity 并尝试向 TextView 添加一个新字符串时。

通常我使用 runOnUiThread(),但此方法在应用程序中不可用 class。谁能帮帮我?

如果我们假设您的 TextView 被称为 tv,请执行:

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