0
This activity is about life cycle on Android, I read several materials but I’m still lost? Can someone please explain.
0
This activity is about life cycle on Android, I read several materials but I’m still lost? Can someone please explain.
0
Take a look here: https://www.tutorialspoint.com/java/lang/system_currenttimemillis.htm
Explain in more detail what I quoted in my last comment. But basically the logic is you use System.currentTimeMillis() to go saving timeframes that you’ll want to measure: when Activity starts, when it pauses, etc.
To measure the time spent between these milestones, just take the difference between them, which will be a value in milliseconds, then just convert to the unit you want (minutes, seconds, etc).
In case this is for pure java, but can implement on android the same way?
Rodrigo, you have very basic doubts. I think you will have a lot of difficulty learning to program Android this way, just asking questions here. I strongly suggest you take a look. I started last year for this course, which is official at Google, and helped me a lot. It’s not big and it’s subtitled in English: https://br.udacity.com/course/android-development-for-beginners--ud837/
Browser other questions tagged android android-activity
You are not signed in. Login or sign up in order to post.
What you don’t understand?
– Márcio Oliveira
I don’t know how to apply a logic to take the time stopped and the time paused, as Timemillis applies?
– Rodrigo Costa
The System.currentTimeMillis() returns a number that represents the current date and time in milliseconds (like, how many milliseconds have passed since the default date, I think 1/1/1970 so far), so you save in a variable, for example "timeInitial = System.currentTimeMillis()". When you want to measure the time passed from the initial time, you will call the currentTimeMillis again, which will generate a number greater than the first and will catch the difference between them (in milliseconds), then only convert to the unit you want (minutes, seconds, etc)
– Márcio Oliveira
I understood the idea of taking the initial time and calculating.
– Rodrigo Costa
Can you give an example of even basic implementation? and the counter works like inside onStop, onStart...?
– Rodrigo Costa
protected void onStart()' super.onStart(); system.out.println(System.currentTimeMillis()); } In the case it has to be displayed in a Textview
– Rodrigo Costa