0

I am trying to find the last activity time of a running service on an android device.I have tried the following.

ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) 
{
if (service.service.getClassName().contains("com.truecaller"))//for example
{
    System.out.println(service.service.getClassName());

    System.out.println(service.lastActivityTime);

    System.out.println(service.activeSince);
}
}

I put a tag for system.out on logcat.i executed the program twice with a gap of a minute between the executions.But the output was exactly the same for both.how is that possible.how do we find the actual last activity time of a service?any help would be much appreciated.

1 Answers1

1

But the output was exactly the same for both.how is that possible.

Quoting the documentation for lastActivityTime:

The time when there was last activity in the service (either explicit requests to start it or clients binding to it).

Presumably, in that minute, nobody called startService() or bindService() for this service.

Quoting the documentation for activeSince:

The time when the service was first made active, either by someone starting or binding to it.

Therefore, this will only change if the service was stopped and then started (via stopService() or stopSelf()) or the process was terminated.

Hence, off the cuff, your results would seem to match the documented behavior.

how do we find the actual last activity time of a service?

I do not know what "last activity time" means with respect to a service.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for your time.u are probably right about the activeSince part of the question.But i got some doubts about the lastActivityTime part.for example i catch whatsapp's servive.i execute it once..tell my friend to send me a message on whatsapp.then execute again..Then the last activity time must have changed right?but its not happening – Abhilash anand Jan 18 '15 at 05:18
  • @user3837789: "Then the last activity time must have changed right?" -- not necessarily. It would depend upon how Whatsapp is written. – CommonsWare Jan 18 '15 at 12:28