src/main/java/org/acra/ErrorReporter.java
/**
     * Try to send a report, if an error occurs stores a report file for a later
     * attempt.
     * 
     * @param e
     *            Throwable to be reported. If null the report will contain a
     *            new Exception("Report requested by developer").
     * @param reportingInteractionMode
     *            The desired interaction mode.
     * @param forceSilentReport
     *            This report is to be sent silently, whatever mode has been
     *            configured.
     * @return A running ReportsSenderWorker that is sending the reports if the
     *         interaction mode is silent, toast or the always accept preference
     *         is true, otherwise returns null.
     */
Try to send a report, if an error occurs stores a report file for a later
attempt.

@param e
Throwable to be reported. If null the report will contain a
new Exception("Report requested by developer").
@param reportingInteractionMode
The desired interaction mode.
@param forceSilentReport
This report is to be sent silently, whatever mode has been
configured.
@return A running ReportsSenderWorker that is sending the reports if the
interaction mode is silent, toast or the always accept preference
is true, otherwise returns null.
Try to send a report if an error occurs stores a report file for a later attempt . @param e Throwable to be reported . If null the report will contain a new Exception ( " Report requested by developer " ) . @param reportingInteractionMode The desired interaction mode . @param forceSilentReport This report is to be sent silently whatever mode has been configured . @return A running ReportsSenderWorker that is sending the reports if the interaction mode is silent toast or the always accept preference is true otherwise returns null .
private SendWorker handleException(Throwable e, ReportingInteractionMode reportingInteractionMode,
            final boolean forceSilentReport, final boolean endApplication) {
        boolean sendOnlySilentReports = false;
        if (reportingInteractionMode == null) {
            reportingInteractionMode = ACRA.getConfig().mode();
        } else {
            if (reportingInteractionMode == ReportingInteractionMode.SILENT
                    && ACRA.getConfig().mode() != ReportingInteractionMode.SILENT) {
                sendOnlySilentReports = true;
            }
        }
        if (e == null) {
            e = new Exception("Report requested by developer");
        }
        final boolean shouldDisplayToast = reportingInteractionMode == ReportingInteractionMode.TOAST
                || (ACRA.getConfig().resToastText() != 0 && (reportingInteractionMode == ReportingInteractionMode.NOTIFICATION || reportingInteractionMode == ReportingInteractionMode.DIALOG));
        if (shouldDisplayToast) {
            new Thread() {
                /*
                 * (non-Javadoc)
                 * 
                 * @see java.lang.Thread#run()
                 */
                @Override
                public void run() {
                    Looper.prepare();
                    ToastSender.sendToast(mContext, ACRA.getConfig().resToastText(), Toast.LENGTH_LONG);
                    Looper.loop();
                }
            }.start();
        }
        final CrashReportData crashReportData = crashReportDataFactory.createCrashData(e, forceSilentReport);
        final String reportFileName = getReportFileName(crashReportData);
        saveCrashReportFile(reportFileName, crashReportData);
        SendWorker sender = null;
        if (reportingInteractionMode == ReportingInteractionMode.SILENT
                || reportingInteractionMode == ReportingInteractionMode.TOAST
                || prefs.getBoolean(ACRA.PREF_ALWAYS_ACCEPT, false)) {
            Log.v(ACRA.LOG_TAG, "About to start ReportSenderWorker from #handleException");
            sender = startSendingReports(sendOnlySilentReports, true);
        } else if (reportingInteractionMode == ReportingInteractionMode.NOTIFICATION) {
            notifySendReport(reportFileName);
        } else if (reportingInteractionMode == ReportingInteractionMode.DIALOG) {
            notifyDialog(reportFileName);
        }
        if (shouldDisplayToast) {
            toastWaitEnded = false;
            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... arg0) {
                    final Time beforeWait = new Time();
                    final Time currentTime = new Time();
                    beforeWait.setToNow();
                    final long beforeWaitInMillis = beforeWait.toMillis(false);
                    long elapsedTimeInMillis = 0;
                    while (elapsedTimeInMillis < ACRAConstants.TOAST_WAIT_DURATION) {
                        try {
                            Thread.sleep(ACRAConstants.TOAST_WAIT_DURATION);
                        } catch (InterruptedException e1) {
                            Log.e(LOG_TAG, "Error : ", e1);
                        }
                        currentTime.setToNow();
                        elapsedTimeInMillis = currentTime.toMillis(false) - beforeWaitInMillis;
                    }
                    toastWaitEnded = true;
                    return null;
                }
            };
        }
        if (sender != null) {
            final SendWorker worker = sender;
            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... arg0) {
                    if (worker != null) {
                        while (!toastWaitEnded && worker.isAlive()) {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e1) {
                                Log.e(LOG_TAG, "Error : ", e1);
                            }
                        }
                    }
                    return null;
                }
                /*
                 * (non-Javadoc)
                 * 
                 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
                 */
                @Override
                protected void onPostExecute(Void result) {
                    super.onPostExecute(result);
                    if (endApplication) {
                        endApplication();
                    }
                }
            };
        }
        return null;
    }
private SendWorker handleException ( Throwable e , ReportingInteractionMode reportingInteractionMode , final boolean forceSilentReport , final boolean endApplication ) { boolean sendOnlySilentReports = false ; if ( reportingInteractionMode == null ) { reportingInteractionMode = ACRA . getConfig ( ) . mode ( ) ; } else { if ( reportingInteractionMode == ReportingInteractionMode . SILENT && ACRA . getConfig ( ) . mode ( ) != ReportingInteractionMode . SILENT ) { sendOnlySilentReports = true ; } } if ( e == null ) { e = new Exception ( "Report requested by developer" ) ; } final boolean shouldDisplayToast = reportingInteractionMode == ReportingInteractionMode . TOAST || ( ACRA . getConfig ( ) . resToastText ( ) != 0 && ( reportingInteractionMode == ReportingInteractionMode . NOTIFICATION || reportingInteractionMode == ReportingInteractionMode . DIALOG ) ) ; if ( shouldDisplayToast ) { new Thread ( ) { /*
                 * (non-Javadoc)
                 * 
                 * @see java.lang.Thread#run()
                 */ @ Override public void run ( ) { Looper . prepare ( ) ; ToastSender . sendToast ( mContext , ACRA . getConfig ( ) . resToastText ( ) , Toast . LENGTH_LONG ) ; Looper . loop ( ) ; } } . start ( ) ; } final CrashReportData crashReportData = crashReportDataFactory . createCrashData ( e , forceSilentReport ) ; final String reportFileName = getReportFileName ( crashReportData ) ; saveCrashReportFile ( reportFileName , crashReportData ) ; SendWorker sender = null ; if ( reportingInteractionMode == ReportingInteractionMode . SILENT || reportingInteractionMode == ReportingInteractionMode . TOAST || prefs . getBoolean ( ACRA . PREF_ALWAYS_ACCEPT , false ) ) { Log . v ( ACRA . LOG_TAG , "About to start ReportSenderWorker from #handleException" ) ; sender = startSendingReports ( sendOnlySilentReports , true ) ; } else if ( reportingInteractionMode == ReportingInteractionMode . NOTIFICATION ) { notifySendReport ( reportFileName ) ; } else if ( reportingInteractionMode == ReportingInteractionMode . DIALOG ) { notifyDialog ( reportFileName ) ; } if ( shouldDisplayToast ) { toastWaitEnded = false ; new AsyncTask < Void , Void , Void > ( ) { @ Override protected Void doInBackground ( Void ... arg0 ) { final Time beforeWait = new Time ( ) ; final Time currentTime = new Time ( ) ; beforeWait . setToNow ( ) ; final long beforeWaitInMillis = beforeWait . toMillis ( false ) ; long elapsedTimeInMillis = 0 ; while ( elapsedTimeInMillis < ACRAConstants . TOAST_WAIT_DURATION ) { try { Thread . sleep ( ACRAConstants . TOAST_WAIT_DURATION ) ; } catch ( InterruptedException e1 ) { Log . e ( LOG_TAG , "Error : " , e1 ) ; } currentTime . setToNow ( ) ; elapsedTimeInMillis = currentTime . toMillis ( false ) - beforeWaitInMillis ; } toastWaitEnded = true ; return null ; } } ; } if ( sender != null ) { final SendWorker worker = sender ; new AsyncTask < Void , Void , Void > ( ) { @ Override protected Void doInBackground ( Void ... arg0 ) { if ( worker != null ) { while ( ! toastWaitEnded && worker . isAlive ( ) ) { try { Thread . sleep ( 100 ) ; } catch ( InterruptedException e1 ) { Log . e ( LOG_TAG , "Error : " , e1 ) ; } } } return null ; } /*
                 * (non-Javadoc)
                 * 
                 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
                 */ @ Override protected void onPostExecute ( Void result ) { super . onPostExecute ( result ) ; if ( endApplication ) { endApplication ( ) ; } } } ; } return null ; }
Try to send a report, if an error occurs stores a report file for a later
 attempt.
Try to send a report if an error occurs stores a report file for a later attempt .
// No interaction mode defined, we assume it has been set during
 // ACRA.initACRA()
 // An interaction mode has been provided. If ACRA has been
 // initialized with a non SILENT mode and this mode is overridden
 // with SILENT, then we have to send only reports which have been
 // explicitly declared as silent via handleSilentException().
 // We will wait a few seconds at the end of the method to be sure
 // that the Toast can be read by the user.
 // Always write the report file
 // Approve and then send reports now
 // Send reports when user accepts
 // Create a new activity task with the confirmation dialog.
 // This new task will be persisted on application restart right
 // after its death.
 // Wait a bit to let the user read the toast
 // start a sender waiting AsyncTask
 // call endApplication() un onPostExecute(), only when (toastWaitEnded
 // == true)
 // We have to wait for BOTH the toast display wait AND
 // the worker job to be completed.
