相关疑难解决方法(0)

如何在Xamarin.Android中正确编写自定义UncaughtExceptionHandler

我想要实现的只是捕获我的应用程序上的异常,以便我可以将它们发送到服务器.我想通了,我可以写我的自定义为此UncaughtExceptionHandler的基础上,原生Android代码Java中回答这里在StackOverflow上.

这是我的CustomExceptionHandler类:

public class CustomExceptionHandler : Thread.IUncaughtExceptionHandler
{
    public IntPtr Handle { get; private set; }

    public CustomExceptionHandler(Thread.IUncaughtExceptionHandler exceptionHandler)
    {
        Handle = exceptionHandler.Handle;
    }

    public void UncaughtException(Thread t, Throwable e)
    {
        // Submit exception details to a server
        ...

        // Display error message for local debugging purposes
        Debug.WriteLine(e);
    }

    public void Dispose()
    {
        throw new NotImplementedException();
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我使用这个类在我的Activity中设置DefaultUncaughtExceptionHandler:

// Set the default exception handler to a custom one
Thread.DefaultUncaughtExceptionHandler …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin.android xamarin

2
推荐指数
1
解决办法
1202
查看次数

标签 统计

android ×1

c# ×1

xamarin ×1

xamarin.android ×1