Abhilash anand
Abhilash anand

Reputation: 127

Get to know the last activity time of a service

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.

Upvotes: 0

Views: 375

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007369

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.

Upvotes: 1

Related Questions