从开始一个Thread.UncaughtExceptionHandler服务? [英] Start a service from Thread.UncaughtExceptionHandler?

查看:368
本文介绍了从开始一个Thread.UncaughtExceptionHandler服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个全球性的异常处理服务作为<一提到href=\"http://stackoverflow.com/questions/601503/how-do-i-obtain-crash-data-from-my-android-application/8427050#8427050\">this回答。这种做法,因为后崩溃听起来合乎逻辑,在code在我的自定义 Thread.UncaughtExceptionHandler 可能无法成功执行,要么是因为应用程序可能无法在一个稳定的状态,或者因为之前的过程中被杀害,可能没有足够的时间操作系统。

I'm trying to setup a global exception handling service as mentioned in this answer. This approach sounds logical because after a crash, the code in my custom Thread.UncaughtExceptionHandler may not execute successfully, either because the application may not be in a stable state or because there may not be enough time before the process is killed by the OS.

不幸的是,这种做法似乎并没有工作,因为该服务在同一进程,因此,也被杀害启动。我该如何开始从处理程序的 uncaughtException服务()?我可以强制服务于一个完全独立的进程来启动?

Unfortunately, this approach doesn't seem to work because the service launches in the same process so it, too, is killed. How can I start a service from the handler's uncaughtException()? Can I force the service to launch in a completely seperate process?

我设置我的定制默认(VM级)异常处理程序中的应用是这样的:

I'm setting my custom default (VM-level) exception handler in Application like this:

public class MyApp extends Application {    
    @Override
    public void onCreate() {
        Thread.setDefaultUncaughtExceptionHandler(
            MyExceptionReporter.getInstance(this));
        ...

在我的自定义处理程序,我推出该服务是这样的:

In my custom handler, I'm launching the service like this:

final Intent i = new Intent(MyExceptionService.INTENT);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(MyExceptionService.EXTRA_STACK_TRACE,
    Log.getStackTraceString(ex));
mContext.startService(i);

该服务在 AndroidMaifest.xml 文件declated并从其他应用程序启动的罚款。

The service is declated in the AndroidMaifest.xml file and launches fine from elsewhere in the application.

推荐答案

嗯,我想通了这一点。关键是为 机器人添加:过程 以清单,强制服务,在一个单独的进程来启动。这prevents从当应用程序被杀害被杀害的服务。

Ah, I figured this out. The key was to add android:process to the manifest, which forces the service to launch in a seperate process. This prevents the service from being killed when the application is killed.

<service
    android:name="your.package.blah.blah.MyExceptionService"
    android:process=":exception" >
    <intent-filter>
        <action android:name="your.package.blah.blah.REPORT" />
    </intent-filter>
    </service>

这篇关于从开始一个Thread.UncaughtExceptionHandler服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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