Question

I have created my own android background service from which - once started - I would like to know for how long it is running. What's the best way to do that? Is there allready a method to find this out, or should I create a timer within the service class? I could start the timer when the service's onStartCommand() is called...but I have the impression that this is an unproper way of creating something that already exists.

Was it helpful?

Solution

Final behavior depends on the kind of service you are using, but in general terms you can always rely on the onDestroy() call of it. If it's a regular (not bound) service, it "should" get destroyed as soon as the execution ends. For bound services, it gets destroyed as soon as all clients unbind from it.

More on services

OTHER TIPS

As Jose L Ugia says above, it depends on the kind of service you are using. But it is not reliable to calculate time like that, because some time android will kill you service, and it wouldn't call the onDestroy(). So create a timer and record time to files is more reliable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top