I have some problems with the order of method in my app. How i can take the control of time in an Android app? How i can know how many time is elapsed from the start of app? For more accuracy, I would say at 3 seconds from the start of this app, i want make happen this, like an invisible chronometer that, at one second, applies a method that i choose. I hope the question is easy to understand. Thanks in advance!
-
read about timers: https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html – hoijui Aug 23 '15 at 16:23
2 Answers
If You want to run task at once only you can use
new Timer().schedule(task, after);
And for multiple time execution
new Timer().scheduleAtFixedRate(task, after, interval);
for more details java.util.Timer.

- 4,321
- 1
- 24
- 35
Take a look of this library, Hugo
https://github.com/JakeWharton/hugo
With this you can control how many time elapsed in the methods.
To control how many time elapsed from app start until, for example, first activity is shown you have to:
First, extends Application class, you have and example here http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/
In the onCreate method of that class, save the time with System.currentTimeMillis()
method
Then create a static method
public long getCurrentTimeFromStart() {
long current = System.currentTimeMillis();
return mInitialTime - current;
}
Call this method in onCreate method of your MainActivity or only the first time is called onResume for a more accurate time.
And for the last question you can use @Keyur Lakhani answer and user Timer class to schelude Runnables

- 7,227
- 4
- 35
- 72