4

Possible Duplicate:
ACRA with android: How to execute code before crash is reported

I am using ACRA for crash reporting. When a crash happens, ACRA reports. how can I execute a code before a crash gets reported? I want to add some custom variables when crash happens so it gets sent along with the report. Is there a function I can override or something like that?

Thanks

Community
  • 1
  • 1
Snake
  • 14,228
  • 27
  • 117
  • 250

2 Answers2

2

ACRA supports this functionality out of the box, as detailed here. Basically, all you have to do is add the following line for whatever custom data you want, at the point you want it:

ErrorReporter.getInstance().putCustomData("myVariable", myVariable);
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • 2
    Yes I know that, but where do I put this line? I need to execute right after a crash (before the crash is reported). You see what I mean, At the time of the crash I need to report myVariable. So I am wondering whats the code the ACRA will always execute upon a crash so I put this ErrorReporter line in – Snake Sep 01 '12 at 19:41
  • 1
    @Snake you hit the nail on the head: yes a major deficiency in all these answers is the assumptive nature of "where you are" for example if you add this in the application extension class it just sends "null" values (for example) if though the user is clearly logged in it doesn't "re-collect" the username for my putCustomData("username", mysettings.getUsername()) call.. how to get it to do that very thing is the question. still shame the forums are 100% full of people banally ignoring this road-stopping isue – user26676 Mar 04 '14 at 14:00
  • PS: posting the massive enormous god sized web page link any man and his dog can find on google is NOT a answer - most of the acra documentation is wrong/old/out of date or a blind alley unrelated to portions of unused functionality – user26676 Mar 04 '14 at 14:03
  • for example these links all talk about making a blank "ReportSender" there is no code on how to putCustomData() in at the ReportSender – user26676 Mar 04 '14 at 14:11
1

If you want to report extra variables, the easiest method is to set them with the ErrorReporter's putCustomData method each time the variable values changes. This way you'll have the correct value if a crash occurs.

Alternatively, you might be able to execute code by implementing your own sender.

Boris Treukhov
  • 17,493
  • 9
  • 70
  • 91
THelper
  • 15,333
  • 6
  • 64
  • 104