1

I'm trying to figure out how I can time how long button presses and stuff take in my android app. Are there tools in the android sdk that do this kind of thing for me? Or is there some sort of industry standard tool I can use to capture this data?

Goishin
  • 45
  • 1
  • 6
  • Worth a read: http://stackoverflow.com/questions/1770010/how-do-i-measure-time-elapsed-in-java – Andy Turner Feb 25 '16 at 23:00
  • Thanks Andy, that was a good read. However, I was kind of looking for a third party app of some type that would allow me to capture this information without editing too much code. I'm a tester on a project with an android app, and I'm interested in capturing timing metrics from the end-user point of view. I thought my question would result in a large number of the latest 3rd party apps that do this. – Goishin Feb 26 '16 at 00:07
  • Question asking for recommendations of third party apps are off-topic. Perhaps look at http://developer.android.com/tools/performance/index.html#cpu-tools, which I found by googling "android profiling tools". – Andy Turner Feb 26 '16 at 07:24
  • Ah, got it. Thanks Andy :) – Goishin Feb 29 '16 at 17:42

1 Answers1

1

The most common way to do this is just take the start time using System.nanoTime() when your code starts and then subtracting that from another call from System.nanoTime().

IE:

long dTime = System.nanoTime() - startTime;

as far as timing a button press use a onTouch listener and then get the start time in the on down event and the calculate the time using the on up event.

Austi01101110
  • 616
  • 4
  • 23
  • Please read the answers on the "Worth a read" I posted in a comment, in particular [Kevin Bourillion's answer](http://stackoverflow.com/a/1776053/3788176) as to why you shouldn't use `System.currentTimeMillis()` for this purpose. – Andy Turner Feb 25 '16 at 23:03
  • Either would work if you didn't care about accuracy but I see your point. Also measuring really long intervals wouldn't work with nanoTime() – Austi01101110 Feb 25 '16 at 23:07
  • ... Never mind 2^63 is 292 years. so use nanoTime() its the better option. – Austi01101110 Feb 25 '16 at 23:15