Periodic update inside UI thread

525 views Asked by At

For a new project in Android I receive the location from various users from a server, which I then need to put on Google Maps as an overlay. Now this al works perfect except it seems impossible for me to change the location for the overlays periodically. I can't use a timer cause it throws the ConcurrentModificationException when I remove and display the overlays again (which i understand why it does that, you can't modify the overlays in another thread). I also can't do this when receiving the new locations because I use websockets to retrieve them and this also works in a different thread.

Now is there some way i can update the UI periodically inside the UI thread, so the overlays can be removed (just moving the overlays would be fine also, but that still requires a periodic update I guess...)?

It seemed like such a simple problem but i've been searching for it for hours and can't find any solution for it...

Any help on how this should be done would be very appreciated!

Greets!

E.

1

There are 1 answers

0
Franci Penov On BEST ANSWER

Creat a Handler on your UI thread and store it in a class variable. Then, on your timer, or in your websocket thread use that handler to post a Runnable with the update code back to the UI thread.