Timer implementation in Android

25 02 2012

Need to perform some action automatically in Android app after specific time period? The internet knows few solutions.

Here is implementation that I use:

1. Create Handler instance and set delayed callback to be called in specified time

Handler mHandler = new Handler();
mHandler.postDelayed(mEndPressedState, 400);

2. Define Runnable that will be triggered after timer passed

private final Runnable mEndPressedState = new Runnable() {
	public void run() {

For implementing a single timed action it is enough to create Handler instance and use postDelayed() method with a reference to Runnable method. For consequent timer calls there is postAtTime() used in a run() method.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!



Give Your feedback:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: