I want to add ACRA library to report exception to app developer but This code working fine when app is running currently but it's shows exception even app is closed.
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
#ReportsCrashes(formUri = "",
mode = ReportingInteractionMode.DIALOG,
mailTo = "xyz#gmail.com",
resDialogText = R.string.reporttous,
resDialogOkToast = R.string.OK,
formKey = "")
public class UILApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
ACRA.init(this);
}
}
Any hint or help will be appreciate
ACRA catches crashes that occur within your app and then optionally notifies user and sends you a crash report. It does so by catching uncaught RuntimeExceptions and processing them.
If ACRA has caught an Exception and displayed a notification dialog, it is because your app was running and threw an uncaught exception.
Do not be confused with not visible in foreground and not running. They are not the same thing.
Related
I am working on an Android library where I need to perform some action if an uncaught exception is seen.
I am successfully setting my uncaught exception handler and running the code I need, which is to post some information to a web server, but after my part is finished I want the app to then do what Android usually does, i.e. display a dialogue to the informing them that it has crashed and then exit the app, and post the details to the Google Play Developer Console.
At the moment, my uncaught exception successfully posts to the server, but then keeps the app running but in a bit of a weird state as the thread has party disappeared, where usually, if my an uncaught exception is thrown, then Android closes the app.
Below is how I am doing my uncaught exception handler:
private static void setUnhandledExceptionHandler()
{
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler()
{
#Override
public void uncaughtException(final Thread thread, final Throwable) {
CrashReporter.ReportUnhandledCrash(((Exception) ex));
Looper.loop();
}
});
}
Basically, what I want to do is, have my app post to to my server via my unhandled exception handler and then quit the app, in the same way that Android usually does, i.e. display a force close error the use and close the app.
I had a similar problem when tracking to GoogleAnalytics - most Exceptions got lost when i tried to report them in the default handler. So i cached them and reported them on the next startup.
The second trick (and this hopefully answers your question) to let the Application crash as it should is to store the 'old' DefaultUncaughtExceptionHandler and pass the exception to it.
The onCreate method below is the one of my Application class
#Override
public void onCreate()
{
super.onCreate();
trackCachedException();
setupExceptionHandling();
}
private void setupExceptionHandling()
{
_systemExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.UncaughtExceptionHandler myHandler = new Thread.UncaughtExceptionHandler()
{
#Override
public void uncaughtException(Thread thread, Throwable ex)
{
cacheException(thread.getName(), ex);
if (_systemExceptionHandler != null)
{
_systemExceptionHandler.uncaughtException(thread, ex);
}
}
};
// Make myHandler the new default uncaught exception handler.
Thread.setDefaultUncaughtExceptionHandler(myHandler);
}
The only way I can see how you can do this is neither clean nor pleasant, so I'll say sorry before we begin...
The order of operations is:
Store the uncaught exception
Log the exception as you have done previously
Deregister your uncaught exception handler, by calling the set method with null.
Launch a new thread that throws your stored exception.
You are effectively throwing the same exception twice, but removing the recovery mechanism on the second throw.
I am trying to debug the widget of the app I'm developing with ACRA but I have a problem. I use the following code to collect the StackTrace:
import org.acra.ACRA;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
import android.app.Application;
#ReportsCrashes(formKey = "",
resToastText = R.string.crash_toast_text, mailTo = "mailAddress", mode = ReportingInteractionMode.TOAST, logcatArguments = {
"-t", "100", "-v", "long", "ActivityManager:I", "MyApp:D", "*:S" })
public class MyApplication extends Application
{
#Override
public void onCreate()
{
super.onCreate();
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
The problem is that it happens on Samsung devices that the widget become unresponsive after a random amount of time and I have no idea what is causing it (I never call onUpdate so nothing should happen but this is another story). I'd like to use ACRA to collect the StackTrace when it becomes unresponsive but when, for example, I turn on the screen after 10 minutes and see the widget not working I have no message from ACRA that has collected a crash report to send me an email and see the problem.
Is maybe ACRA not working?
If the widget is not responsive (the buttons for example) it means it crashed right?
Do you have any better strategy to debug this situation?
Thank you very much
If the widget is not responsive, then it hasn't crashed, it is in some kind of deadlock or waiting state. That is why you haven't received any message from ACRA.
Either looks at what the threads are doing, or injecting a healthy amount of debug to try to determine what has locked up the app.
I am working on an Android Application which is integrated with MixPanel for analytics and BugSnag for error monitoring.
Recently we found crash in the application and as we couldn't find the root cause of the crash we added code to restart the app when the bug occurs. Along with restart, we also started tracking how many times the bug occurs. My preference was to use Bugsnag for the same, but couple of people in the team asked why can't we use MixPanel because we can easily filter out the events with parameters which we sent to MixPanel. But I feel MixPanel shouldn't be used as its specifically for tracking user events. And neither the crash nor the restart happens because of a user event, it just happens randomly.
I would like to hear suggestions/thoughts from the community regarding the same.
You could use Thread.setDefaultUncaughtExceptionHandler(...) in your Application.onCreate to set your custom Thread.UncaughtExceptionHandler that tracks to MixPanel all the UncaughtExceptions (Crashes) and set properties such as :
public class MyExceptionHandler implements UncaughtExceptionHandler
{
private UncaughtExceptionHandler defaultExceptionHandler;
public MyExceptionHandler (UncaughtExceptionHandler defaultExceptionHandler)
{
this.defaultExceptionHandler = defaultExceptionHandler;
}
public void uncaughtException(Thread thread, Throwable exception)
{
mMixPanelInstance.trackEvent("APP_CRASH", null);
if (defaultExceptionHandler != null)
{
defaultExceptionHandler.uncaughtException(thread, exception);
}
}
}
MyApplication.onCreate(...)
{
UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(currentHandler));
}
In my Android application I utilize setDefaultUncaughtExceptionHandler to store information about unhandled exceptions locally on a user device. After some feedback I suspect that this code prevents the built-in Google's error-reporting feature from work, because I do not see error reports in the developer console, while exceptions are reported by users. Their devices are well past 2.2, where the error-reporting was introduced. Could it be that specific device with, say, 4.0.3 does not support this feature? If yes, how can I detect this programmatically?
I can't find information regarding this in Android documentation. I'd like both standard error-reporting and my custom handling work together. In my custom exception handler I call Thread.getDefaultUncaughtExceptionHandler() to get default handler, and in my implementation of uncaughtException I propagate exception to this default handler as well.
I first tried calling System.exit(1); as mentioned in this SO answer, but that didn't work.
Finally solved it by calling the uncaughtException(Thread thread, Throwable ex) again on Androids default UncaughtExceptionHandler (found it by checking the ACRA source code.
Example Activity
public class MainActivity extends Activity implements Thread.UncaughtExceptionHandler {
private Thread.UncaughtExceptionHandler _androidUncaughtExceptionHandler;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_androidUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
// Rest onCreate
setContentView(R.layout.main_activity);
}
//#Override
public void uncaughtException(Thread thread, Throwable ex) {
try {
// Do your stuff with the exception
} catch (Exception e) {
/* Ignore */
} finally {
// Let Android show the default error dialog
_androidUncaughtExceptionHandler.uncaughtException(thread, ex);
}
}
}
Yes, this will stop the inbuilt error report. The user is given a dialog when your app crashes, with an option to report the error via Google Play. However, if you use setDefaultUncaughtExceptionHandler() then the exception is handled within your app, and no option is given to report it.
I recommend that you integrate ACRA into your project, as it allows you to easily receive error reports upon crashes.
i have being using ACRA ,which is a library enabling Android Application to automatically post their crash reports to a GoogleDoc form.
i have been using following code in OnCreate of Application
#ReportsCrashes(formKey = "XXXXXXX", mode=ReportingInteractionMode.TOAST,
forceCloseDialogAfterToast = false,resToastText = R.string.crash_toast_text)
public class MyApplication extends Application{
#Override
public void onCreate() {
// The following line triggers the initialization of ACRA
ACRA.init(this);
super.onCreate();
}
}
When i First test it i got response in ACRA CrashReport form(In form of Google Doc) but for next time for same crash i didnt get response whenever any crash/exception occur in my android application.
Check that you set all permissions needed ACRA. It depends on fields that you want in report, some of them need READ_LOGS permission or READ_PHONE_STATE permission
(for more http://code.google.com/p/acra/wiki/ReportContent)
If error still present and connected with report sending on Google Doc try to add custom timeout:
#ReportsCrashes(formKey = "xxxxxxxxx", socketTimeout = 25000)