Send stack trace information to backend server from android app on app crash

六眼飞鱼酱① 提交于 2021-01-20 11:59:53

问题


We are in the process of writing a realtime error handling web platform, and I am trying to find out what is the best way to send the stack trace information via an http post request back to our server as soon as the android app crash occurs.

I already use the Thread.setDefaultUncaughtExceptionHandler callback to register our callback handler so we can capture the stack trace. Hover I can't seem to make an http request right after the app crashes for some odd reason (behaviour is very weird, the response/error callbacks are not called at all if I make the request in the error handler part of the code, so my guess is the http request is not reliable at all if invoked there).

I also tried starting up an IntentService in the global exception handler so I can make the request from there but the service just wont start after the app crashes. I don't know what to try next.

I need to be able to send the error to our server straight away, without using 3rd party crash reporting services (because this is what we're building ourselves). Any hints as to what I could try next?


回答1:


@CommonsWare's recommendation ACRA is a really good solution.

But regarding:

[...] post request back to our server as soon as the android app crash occurs. [...] I need to be able to send the error to our server straight away [...]

Saving the report to send later, you can force the app to restart, and send the saved report on restart with a clean stack.

I used something like Ereza/CustomActivityOnCrash library to do it, what it does:

Allows launching a custom activity when the app crashes, instead of showing the hated "Unfortunately, X has stopped" dialog.

So basically it "kills" your crashed application, then start a fresh one with a friendly activity.

I used it to show an Activity telling the user that we already received the crash, asking to write down more directions to help us solve the issue and if the user wanted to be contacted upon bug fix.




回答2:


I ended up using ACRA library following @CommonsWare's advice



来源:https://stackoverflow.com/questions/48311194/send-stack-trace-information-to-backend-server-from-android-app-on-app-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!