次数的服务已运行次数

由网友(施主↘化个妞)分享简介:我在我的应用程序三项活动,所有这些活动需要访问服务。所以,如果我启动服务三次将它启动三次或一次。而如果一旦将previous数据被删除时,服务重新启动。I have three activities in my app and all those activities requires access to servi...

我在我的应用程序三项活动,所有这些活动需要访问服务。所以,如果我启动服务三次将它启动三次或一次。而如果一旦将previous数据被删除时,服务重新启动。

I have three activities in my app and all those activities requires access to service. So if i start the service three times will it be started three times or only once. And if once will the previous data be erased when service is restarted.

感谢名单

推荐答案

如果你正着手与 startService 服务,那么第一次的的onCreate 方法将被调用,这不要紧,你有多少次启动该服务,但它的方法 onStartCommand(意向,INT,INT)将被称为对于你的startService电话。当你调用 stopService 不管你有多少次叫 startService 服务停止。

if you are starting service with startService then for first time it's onCreate method will be called and it does not matter how many times you have started the service but its method onStartCommand(Intent, int, int) will be called with respect to your startService call. Service stops when you call stopService irrespective of how many times you have called startService.

不要忘了释放资源,线程,当你停止servive。

Don't forget to release the resources, threads when you stop the servive.

您可以参考这个文档:

http://developer.android.com/reference/android/app/Service.html

阅读全文

相关推荐

最新文章