如果Android的服务崩溃,它会降低应用程序上运行它? [英] If Android service crashes will it bring down App on which it is running?

查看:90
本文介绍了如果Android的服务崩溃,它会降低应用程序上运行它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个服务一个Android应用程序组件,我想我的应用程序不是因为在任何服务故障崩溃。默认情况下为应用程序被保护的后台服务所有出现故障的行为。

I'm writing a service for an Android application component and I want my App to not crash because of any fault in service. By default Is the app is protected from any faulty behavior of background service.

推荐答案

要回答你的问题,即可。如果你的应用程序崩溃内的服务。照片提供了解决方案,不要让服务崩溃您的应用程序将被终止。我相信你可以prevent崩溃,如果你可以在$应用程序的对$ pvent整个休息的服务。使用的try-catch 或处理异常等编程方法。让我们知道,如果在特定code有什么需要帮助,为这些目的。

To answer your question, Yes. Your application will be terminated if a service within your application crashes.
To provide a solution, don't let the service crash. I believe you can prevent a service from crashing if you can prevent whole rest of application. Use try-catch or other programming approaches to handle exceptions. Let us know if anything specific in code needs help for those purposes.

更新:我是假设您正在使用单进程模式。
由于意见建议,有更多的给它。您的过程将被终止如果该进程崩溃内的服务。如果主线程同一个进程中运行你的应用程序将被终止。结果
默认情况下,Android使用整个​​应用程序相同的过程。在这种情况下,应用程序将在出现任何异常(因为该过程坠毁)被终止。您可以指定不同的进程下表现不同的活动(如果你真的需要它)来运行。结果
请参见进程和线程关于如何做到这一点的更多细节。

Update: I was assuming you are using "single process model". As the comment suggests, there is more to it. Your process will be terminated if a service within that process crashes. Your application will be terminated if the main thread is running under same process.
By default, Android uses same process throughout your application. In that case, the application will be terminated if any exception occurs (because the process is crashed). You can specify different processes to be run for different activities under manifest (if you "really" need it).
See Process and thread for more details on how to do it.

这篇关于如果Android的服务崩溃,它会降低应用程序上运行它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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