stopService不停止的我的服务....为什么? [英] stopService doesn't stop's my service.... why?
问题描述
我有我的Android应用程序是得到我的GPS位置并将其发送到远程数据库后台服务。它的工作的罚款。
i have a background service on my android APP that is getting my GPS position and sending it to a remote db. It work's fine.
现在的问题是,当我想停止的服务....它不会停止:秒。同样也不例外或错误的logcat出现......它根本没有停止。
The problem is when i want to stop the service.... it doesn't stops :S. Also no exception or errors on logcat have appeared... it simply doesn't stops.
这是在code开始我srvice(一个按钮):
this is the code to start my srvice (with a button):
startService(new Intent(GPSLoc.this, MyService.class)); //enciendo el service
这是在code,我停止它(在onactivityresult法):
this is the code where I stop it (on the onactivityresult method):
stopService(new Intent(GPSLoc.this, MyService.class));
我一直在调试的应用程序,我检查了stopService $ C $克莱因被称为每次我调试它的时间,但它不会停止......
I have been debugged the app, and i checked that the stopService codeline has been called every time that i debugged it, but it doesn't stops......
我敢肯定,它没有停止的原因在我的数据库,我仍然recive GPS位置从模拟器当我有preSS按钮停止该项服务。
i am sure that it's not stopped cause on my database i still recive gps positions from the emulator when i have press the button to stop the service.
我在做什么不好?
推荐答案
您是否落实的onDestroy()
?如果不是这样,我认为这可能是解决办法 - 你停止你的定时器
或任何你正在使用运行在的onDestroy服务()
。
Have you implemented onDestroy()
? If not, I believe that might be the solution - and you stop your Timer
or whatever you're using to run the service within onDestroy()
.
一个服务可以通过调用其stopSelf()方法可以停止,或致电Context.stopService()。
A service can be stopped by calling its stopSelf() method, or by calling Context.stopService().
有关更多信息,请参阅此链接。
See this link for some more information.
这篇关于stopService不停止的我的服务....为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!