I am developing a game for Android 2.1
My game is a card playing game. So, what I want is that after I have clicked on one of my cards and I throw it, I want the AI to play his card after 2 seconds. So, to do this I want one of my instance methods to be invoked after 2 seconds of my input.
I have researched some and have found out that Timer class is not supported by Android. I have used Handler class but I did not provide what I want. It works generally but sometimes (almost half of the time) it fails and starts to answer instantly after I have played my card.
So, I want to ask it more generally. In my situation what is the best way of achieving this latency in Android exactly(not certain but almost exactly)??
AsynchTask is best choice, as it schedules execution on UI thread ( only this thread is allowed to interact with UI). Alternatively you could spawn new thread, wait sleep() there, and invoke runOnUiThread(). This may be easier for you, but you will have to stop this thread in case your game activity gets paused. ( AsyncTask will do this for you automagically )