I have created a basic game that runs in a view. It consists of a thread which repeatedly calls the
draw(Canvas canvas) method. Everything works fine so far.
Next, I want to implement a UI that consists of a textView showing the score, and other stats of the game. This is put above the view of the main game. Should this UI have its own thread that repeatedly checks to see if the score has changed, and then update that change in the UI?
At first I just made a class that allows the main game thread to update elements in the UI via something like
But this leads to some instability, and that object to talk to the UI has to be passed throughout the methods in the main game UI which isn't the cleanest approach.
What is the standard approach for implementing the UI in a clean way which is easy to maintain.