Reputation: 7539
I need to store and send crash log to server. I am able to save crash log in preference before it exists, but the problem is that it restarts the application and does not display the default crash message to user.
I want the crash flow for user to be normal.
public void registerCrash(){
Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException (Thread thread, Throwable e)
{
handleUncaughtException (thread, e);
}
});
}
public void handleUncaughtException (Thread thread, Throwable e)
{
thread.getStackTrace();
saveDataToFile(e.toString());
System.exit(-1);
}
If i change the System.exits(0)
, it abruptly crashes, and does not save any log in file, and with System.exit(-1);
, it restarts the application on crash.
Edit
saveDateToFile()
SharedPreferences sharedPreferences= context.getSharedPreferences(CRASH_LOG, Context.MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
prefsEditor.putString(STACK_TRACE, data);
prefsEditor.apply();
Upvotes: 0
Views: 1039
Reputation: 39539
Please have a look at https://github.com/ligi/tracedroid - it can collect the crash-logs for you and you can write your own sending module
Upvotes: 0