문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top