Android的停止服务的崩溃 [英] Android Stop Service on Crash

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

问题描述

我正在运行服务,并在极少数情况下,我的应用程序崩溃会自动将其杀死我的服务吗?我不希望它继续如果这种情况发生。

I am running a Service and am wondering in the rare case that my app crashes will it automatically kill my Service too? I don't want it continuing if this happens.

如果没有,有没有办法做到这一点,如在的onDestroy()方法?

If not, is there a way to do this such as in the onDestroy() method?

推荐答案

我已经做了一些研究,我觉得我有一个完整的回答你的问题。

I've done a bit of research, and I think I have a complete answer to your question.

子类化服务是好的,你不是在不同的进程使用远程服务(A 服务假设。)假设你的服务是相同的过程你的活动,他们都会一起结束,在事件崩溃。既然如此,我早先提出的建议使用 BoundService 不会实际生产不同的结果,并基于对应用程序组件Android的过程中是如何工作的一个有缺陷的认识。

Subclassing Service is fine, assuming you're not using a Remote Service (a Service in a different process.) Assuming your Service is in the same process as your Activity, they'll both end together, in the event of a crash. That being the case, my earlier suggestion to use BoundService wouldn't have actually produced a different result and was based on a flawed understanding of how Application Components work in Android processes.

从<一个报价href=\"http://stackoverflow.com/questions/10699685/android-bound-service-should-i-manually-reconnect-in-onservicedisconnected-or\">Android绑定服务 - 我应该手动onServiceDisconnected重新连接或尝试重新连接自动的:

本地服务:

服务在同一进程中的其他组件的运行(即
  从同一个应用程序绑定到它)的活性,当该单
  应用程序范围的进程已崩溃或者被杀死,这是非常
  可能在此过程中的所有组件(包括活性即
  绑定到该服务)也被破坏了。

Service is running in the same process as other components (i.e. activity that bound to it) from the same application, when this single application-scoped process has crashed or been killed, it is very likely that all components in this process (include the activity that bound to this service) are also destroyed.

此外,您还可以阅读远程服务比。本地服务

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

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