I have 4 Views and I want that the first View gets Visible then after two seconds Invisble then should the next View get Visible and after 2 seconds again Invisible and so on to infinity which View is selected this is random.
Up to know I tried to make 4 Threads for each View one, so whenever a View is selected the corresponding Thread is started. When just one View is selected this works very well I worked with
handler.sendEmptyMessage(0) for setting the View Visible and
handler.sendEmptyMessageDelayed(1, 2000) for setting the View Invisible after 2 seconds.
But when more Views than one are selected this only works for the last View, which was selected. And I think this is the case, because the MainThread executes his MessageQueue only after all Threads are done with work. So I need a Method that the MessageQueue is always executed(And UI changed) when a Thread is finished.
When you have multiple threads running, you have no way of guaranteeing that any particular one will run before / during / after another.
It would be better to simply have one thread that sends an empty message every two seconds. When that message is received, hide the previously visible View, randomly select the next one to show, and show it.