Dave's Brain

Browse - Programming Tips - How can I use sendMessageAtTime() with epoch time?

Date: 2017jan18
OS: Android
Keywords: example

Q.  How can I use sendMessageAtTime() with epoch time?

A.  sendMessageAtTime() expects uptimeMillis so you need to convert your time.

boolean sendMessageAtEpochTime(Handler handler, final Message msg, final long epochTime) { final long diff = epochTime - System.currentTimeMillis(); final long when = SystemClock.uptimeMillis() + diff; return handler.sendMessageAtTime(msg, when); }
You can also use
return handler.sendMessageDelayed();
But I see in the Android source that it just calls sendMessageAtTime();

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.