0

In my app I start a nanoTime in this way:

long startTime = System.nanoTime(); 

now I want that at a specific value of 'startTime' (ex: 1000000) is called a method "myMethod"

private void myMethod(){
    //all operations
}

what's the best way to do it?

JodaStephen
  • 60,927
  • 15
  • 95
  • 117
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
  • 1
    Why don't you post a `Runnable` with a delay instead? Alternatively, if we're talking minutes/hours/days in the future, check out the documentation on `AlarmManager`. – MH. Nov 20 '14 at 11:07

1 Answers1

0

No, you aren't starting anything, just taking the current time.

https://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#nanoTime()

If you want to start a Runnable at a certain time, use Handler.postAtTime()

http://developer.android.com/reference/android/os/Handler.html#postAtTime(java.lang.Runnable, long)

For example

private Handler mHandler = new Handler();
...
mHandler.postAtTime(SystemTime.uptimeMillis() + 1000, new Runnable() {
...
});
HappyCactus
  • 1,935
  • 16
  • 24