4

I have an activity and I have a thread that runs when the activity is started. The thread call one method called getTimeOfLastEvent,

public long getTimeOfLastEvent(){
return 0;
}

I want this method to return me for example milliseconds from the time when the last event happened to this moment(the moment when the method is called). with the word 'event' I refer to any touch on the screen. And for example if the user touches the screen and then leave the phone for a 4 seconds and in that moment the getTimeOfLastEvent is called I want this method to return me 4 seconds (probably in unit milliseconds)

If I leave the phone after 10 seconds the screen is turned off, but if I touch the screen just before the 10 seconds pass, the timer i reset and I got another 10 seconds..., my problem is that I do not know how to read this timer.

Lukap
  • 31,523
  • 64
  • 157
  • 244

1 Answers1

0
static long timeLastEvent ;//initialize with appropriate value


public long getTimeOfLastEvent()
{
long duratin =  System.currentTimeMillis() - timeLastEvent ;
timeLastEvent = System.currentTimeMillis();
return duration ; 
}
Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
  • 1
    the user might press the home button do some things and return to my activity, I do not need to control just for my activity... I need the value from the system, the value upon which is decided if the screen will be turned off – Lukap Nov 10 '11 at 21:28
  • This method works for me...but i don't know where to call it. I need that every 60 seconds a viewflipper to start. – Gabrielle Nov 28 '11 at 10:48
  • This doesn't address the issue of when the last touch happened at all. – Matthew Read May 11 '15 at 18:08