Domanda

How do I debug an app crash when the device is not connected to the eclipse debugger? There are 2 category of crashes, one is when a particular action is performed and the app crashed right away, these a easily reproducible, since I can connect the device to the computer and perform the same operation. There is another category of crashes, usually happen when the app has been idle/in the background/device screen off/etc... and when the app is restarted and brought into the foreground, it crashes. With this category of crashes, I don't know where the crash occurred, any suggestions on how to debug these types of crashes?

Thank you.

È stato utile?

Soluzione

you can use uncaughtExceptionHandler interface for this. simply create class like this :

public class ExceptionHandler implements UncaughtExceptionHandler{

Utils utils ;
Context context;
private final String LINE_SEPARATOR = "\n";

public ExceptionHandler(Context con) {
    // TODO Auto-generated constructor stub
    context = con;
}

@Override
public void uncaughtException(Thread arg0, Throwable arg1) {
    // TODO Auto-generated method stub

    StringWriter stackTrace = new StringWriter();
    arg1.printStackTrace(new PrintWriter(stackTrace));
    StringBuilder errorReport = new StringBuilder();
    errorReport.append("************ CAUSE OF ERROR ************\n\n");
    errorReport.append(stackTrace.toString());

    errorReport.append("\n************ DEVICE INFORMATION ***********\n");
    errorReport.append("Brand: ");
    errorReport.append(Build.BRAND);
    errorReport.append(LINE_SEPARATOR);
    errorReport.append("Device: ");
    errorReport.append(Build.DEVICE);
    errorReport.append(LINE_SEPARATOR);
    errorReport.append("Model: ");
    errorReport.append(Build.MODEL);
    errorReport.append(LINE_SEPARATOR);
    errorReport.append("Id: ");
    errorReport.append(Build.ID);
    errorReport.append(LINE_SEPARATOR);
    errorReport.append("Product: ");
    errorReport.append(Build.PRODUCT);
    errorReport.append(LINE_SEPARATOR);
    errorReport.append("\n************ FIRMWARE ************\n");
    errorReport.append("SDK: ");
    errorReport.append(Build.VERSION.SDK);
    errorReport.append(LINE_SEPARATOR);
    errorReport.append("Release: ");
    errorReport.append(Build.VERSION.RELEASE);
    errorReport.append(LINE_SEPARATOR);
    errorReport.append("Incremental: ");
    errorReport.append(Build.VERSION.INCREMENTAL);
    errorReport.append(LINE_SEPARATOR);


    Intent i = new Intent(context,ExceptionActivity.class);
    i.putExtra("exception",errorReport.toString());
    context.startActivity(i);


    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(10);





}

}

and then in every activity,after setContentView type

Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));

and then by looking at the exception you can determine where error or exception occured.

Altri suggerimenti

Use Bugsense or crashlytics for these kind of purpose

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top