Im currently posting some data to a php webservice using a class that extends AsyncTask.
Now i need to make a synchronous call, because i want to show the default exception popup that my app has crashed once the data is sent (previousHandler.uncaughtException(t, e)).
Can i just disable the async functionality on the AsyncTask, or do you have any other suggestions
Here is my current code, thanks in advance:
public void uncaughtException(Thread t, Throwable e) {
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
e.printStackTrace(printWriter);
String stacktrace = result.toString();
printWriter.close();
String deviceUuid = Utilities.DeviceUuid(ctx, cr);
String bluetoothName = Utilities.LocalBluetoothName();
AsyncTasks.ErrorLogTask logTask = new AsyncTasks.ErrorLogTask(e, bluetoothName, deviceUuid, stacktrace);
logTask.execute();
//task wont be complete before this code below runs since its async.
previousHandler.uncaughtException(t, e);
}
I think you still need to catch the exception. I would keep the call in your AsyncTask, but catch the exception. Either use a flag as the return value from
doInBackgroundor create a variable local to the AsyncTask to use as a flag, and in youronPostExecutecheck for the flag and show a dialog if necessary.In general you don’t want to make a server call on the main UI thread because of the risk of ANRs. See this article on them:
http://developer.android.com/guide/practices/responsiveness.html