0

We released an android APP several years ago, and there's a View.setVisibility() method used in a sub thread. It has been no problem in these years until Android O Developer Preview 4. When I test our APP on Android O Developer Preview 4, I found View.setVisibility() in a sub thread will throw a exception as follows:

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

I've moved this method to main thread and fixed this problem.

But my questions are:

  1. Why is no exception thrown in previous versions(even no exception in Android O Developer Preview 1)?

  2. What change in Android O leads to this problem? We should explain it to our customer but we can't find the proof on Android developer's website.

1 Answers1

2

This exception was thrown in previous versions. It's just never been thrown reliably. Regardless, it's always been wrong to access UI elements from a background thread. Your code is not thread safe, and it's possible that it has always exhibited subtle bugs that have gone unreported. You should fix your code.

Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82