Skip to content Skip to sidebar Skip to footer

Custom Timeout For A Method - Android

In my android app, I'm using a method that tries to get the user's current location in a custom java class. I would like to set a timeout that, when it expires, can do whatever I w

Solution 1:

You can do this in many ways

TimerTask

CountDownTimer

Thread.sleep() (on a background thread, please)

Runnable

You have many options, it just depends on how you want to implement it and what you need. There are many examples and tutorials for each on The Google and SO.

CountDownTimer sounds pretty good for this because you can set the time in millis and do what you want in onFinish() but any could work.


Post a Comment for "Custom Timeout For A Method - Android"