I'm building an app that sometimes crashes, I want to know that it crashed in the next time I opened it so I can suggest to the user some post-crash options. How can I detect the crash? Also I want to be able to save the user's work before it crashes, I means real time detection of crash, can I do it without knowing where it crashed?
5 Answers
You will need to know where it crashed in order to set the try
/catch
blocks in the right place to, er, catch
the crash and save the data or whatever you have in mind.
This is known as "graceful" termination if you want to consider it in more detail.
Unfortunately neither Java destructor/finalize methods nor lifecycle methods such as onDestroy
are anywhere near as robust as try
/catch
blocks so I'm afraid that is your only option, and how many of us deal with exception prevention. No-one would wittingly provide a user experience that crashes, much less with loss of their data.

- 6,433
- 7
- 47
- 82
Take a took at the ACRA library. You can configure it so whenever a crash happens you can control it and even send the crash log by email

- 7,409
- 6
- 27
- 46
You can use try/catch
blocks, then send details on the Exception
in your catch
.

- 8,173
- 4
- 29
- 48
-
yeah... i know that method but i dont want to do try/catch to each if – alon Sep 20 '15 at 12:56
There are implement UncaughtExceptionHandler as mentioned in these answers and write crash report in some file or use it another way.

- 1
- 1

- 8,949
- 11
- 57
- 93
ACRA is already mentioned.
However for paid version, I found BugSnag is very good at this. Or if you want to take the extra mile, try AppSee.
AppSee even has video recording session of how the crash happens. It is from tapping that button on the second list, the menu button or even when the user slides left in your viewpager.

- 1,853
- 2
- 24
- 41

- 1,508
- 16
- 21