How do i change the background of a LinearLayout via setBackgroundColor() by another thread?
I learned, that the Android UI Framework is not threadsafe, so you can’t change UI elements by another Thread than the UI thread.
My goal is to create a strobe light effect by calling the setBackgroundColor() method with changing colors (in this case black/white/black/ect,) on a LinearLayout which fills the entire screen.
One way is to use
Handlerwith message queues. You instantiate theHandlerin the main UI thread, then useobtainMessage()to send messages to theHandler. So an example would be likeThen in your thread you can call:
The result if called once will be
myTextViewnow says “arg1 = 10; arg2 = 20; test”.