My application performs a number of UI updates in close proximity, for example:
- User takes a turn, and all gridview tiles are updated
- AI takes a turn, and all gridview tiles are updated
- AI takes another turn and all gridview tiles are updated
To get each of these updates to be visible to the user, I added each of these update tasks to a Handler on a non-UI thread. These Adapter’s notifyDataSetChanged() tasks are then added to the UI thread’s handler.
However, the only way I can get each update to be clearly visible is to specify a Thread.sleep() after I invoke the update. Even with this sleep, sometimes 2 & 3 are merged together and the user will only see 3.
As well as this, when 3 is performed sometimes it will take an extra split-second to update the entire grid. So rather than there being 3 clean updates of the grid, the user will seee 4.
As far as I can see, I am performing the Handler functionality as recommended by the programming guide. Therefore, I am wondering what else can I do to get better control of when the UI updates? Is there anything I can do?
This has been answered by dmon above.
Solution involved posting a Runnable to GridView.post() after I called notifyDataSetChanged in my adapter.
Game runs a little slower than before, but at least all UI operations render correctly.