Android: check value of System.nanoTime

160 views Asked by At

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?

1

There are 1 answers

0
HappyCactus On

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() {
...
});