StopSelf不会停止我的服务 [英] StopSelf does not stop my service

查看:487
本文介绍了StopSelf不会停止我的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌搜索的时候,我已经看到了这个问题发表了很多次,有些职位在这个论坛上,去年的几年。我从来没有见过任何人都得到一个明确的答案。

Googling around, I have seen this problem posted many times, some of the posts on this forum over that last few years. I have never seen anyone get a straight answer.

我试图做一个this.StopSelf运行2小时后自行停止()一个前台服务。我已经试过了,当它的约束,当它的绑定。在AVD和设备上。

I have a foreground service that tries to stop itself after running for 2 hours by doing a this.StopSelf(). I've tried it when it's bound and when it's unbound. On the AVD and on a device.

这根本不​​起作用。这是Android的一个错误? (运行2.3.3)。

It simply does not work. Is this a bug in Android? (running 2.3.3).

如何才能服务站本身?

推荐答案

如果您使用的是前台服务,你应该叫:

If you use a foreground service, you should call:

<一个href="http://developer.android.com/reference/android/app/Service.html#stopForeground%28boolean%29"><$c$c>stopForeground(true);

就像你启动 startForeground

stopSelf 是指用于正常的服务。前台服务是特殊的...:)

stopSelf is meant to be used for normal services. a foreground service is special... :)

顺便说一句,如果您的应用程序应该在较旧的设备,应检查所提供的兼容性code <一个href="http://developer.android.com/reference/android/app/Service.html#startForeground%28int,%20android.app.Notification%29">here.

By the way, in case your app should work on older devices, you should check the compatibility code offered here.

这篇关于StopSelf不会停止我的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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