次数的服务已运行 [英] Number of times the service has run

查看:110
本文介绍了次数的服务已运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序三项活动,所有这些活动需要访问服务。所以,如果我启动服务三次将它启动三次或一次。而如果一旦将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.

您可以参考这个文档:

<一个href="http://developer.android.com/reference/android/app/Service.html">http://developer.android.com/reference/android/app/Service.html

这篇关于次数的服务已运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆