I am a Java newbie and an Android newbie too. I am working on a game and trying to understand the exact nature of events in Java and Android. I have a few questions to help understand the correct way to do event handling in my app.
Its a network game and so I need to check if the user made a move or not to update the view. Also I need to prompt the user to make a move if he takes too long. For this I have two threads –
- Timer thread expires every 10 seconds and calls updateview if needed or prompts user to make a move.
- Event thread gets created when user clicks on the screen to make a move or clicks on menu etc.
Is this the correct approach? These two can be fired at any time.
Here are the issues I see with this –
- What happens when one thread gets run when the other one is active.
- Which thread has precedence if both are started at the same time.
- Do events in the timer thread get queued up?
- If so can I pick which one in the queue to use?
- Can I cancel events in the queue? For e.g. if I have 2 updateview events lined up in the queue I only have to call it once.
Thanks for any inputs.
P
I would suggest reading up on Android AsyncTask.