I'm making a basic android game, I have a fragment that displays the game world. When I open that fragment I create a new thread that just waits until my NetworkThread
gets the world from the server. Also my GetWorldThread
is a static
Thread
that I only initialize inside the fragment.
This is how my GetWorldThread looks like:
synchronized (this)
{
try
{
Log.d("getWorldThread", "waiting()");
wait();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
and my NetworkThread
looks like this
if (buffer instanceof World)
{
synchronized (WorldFragment.getWorldThread)
{
World.setWorld(((World) buffer));
Log.d("NetworkThread", "notifying World");
WorldFragment.getWorldThread.notify();
}
}
My code works, but I want to know if there is a way to do this more elegant?.