The service in my app cant be always active, so i call startServ开发者_运维知识库ice() when i need and after that, i call stopService().
But sometimes, when (in rare cases) the user uses some features of my application, the service can be started and stopped several times. I wonder if there is any performance issue with this (starting and stopping the service several times), because in the emulator works fine. There is a better way of doing this?
If you're using the service to run short tasks and then immediately stop, why not check out AsyncTask?
The on{Pre,Post}Execute() methods are also useful for interacting with your UI thread based on the inputs/results to the AsyncTasc.
If with emulator all is ok then don't worry. It rather slower than any real android device.
In general, don't bother yourself with the performance until you clearly see an issue. At this moment measure the time, find the place with issue, optimize it and ensure that the time went down and issue is gone.
精彩评论