2015-04-27 24 views
1

它適用於Android 5.0,但它不適用於Jellybean設備。如果我使用ACRA,則不會調用Android UncaughtExceptionHandler

@ReportsCrashes(
    formKey = "", // This is required for backward compatibility but not used 
    formUri = "dummyurl", 
    reportType = org.acra.sender.HttpSender.Type.JSON, 
    httpMethod = org.acra.sender.HttpSender.Method.PUT, 
    formUriBasicAuthLogin="adminTest", 
    formUriBasicAuthPassword="adminTest", 
    mode = ReportingInteractionMode.TOAST, 
    resToastText = R.string.crash_toast_text) 
public class Application extends Application { 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     init(); 
     ACRA.init(this); 
     Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler); 
    } 

    private UncaughtExceptionHandler sUncaughtExceptionHandler = new UncaughtExceptionHandler() { 
     @Override 
     public void uncaughtException(Thread thread, Throwable ex) { 
      Log.i(LogTag, "uncaughtException: "); 

      dummyMethod(); 

      Thread.getDefaultUncaughtExceptionHandler().uncaughtException(
       thread, ex); 
     } 
    }; 
} 
+0

我不知道它爲什麼在L中工作,但這裏錯了,你要設置兩個你手動分配的UncaughtExceptionHandler,一個ACRA正在爲你創建,這是不對的。 –

回答

4

ACRA設置自己的UncaughtExceptioHandler執行錯誤報告,然後委託給之前已存在的任何UncaughtExceptionHandler的。

所以,如果你想叫你的UncaughtExceptionHandler一旦ACRA已經完成了錯誤報告,那麼你需要前將異常處理程序調用ACRA.init(this);

既然你要發送Toast通知您還需要設置forceCloseDialogAfterToast因爲假設defaultExceptionHandler是Android框架中的一個,它將顯示強制關閉對話框,並且如果還顯示Toast,則不想顯示該對話框。

+0

我試過這個, Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler); ACRA.init(this);但仍不起作用, – akk

+0

也設置'forceCloseDialogAfterToast'爲true。 – William

+0

在調用ACRA.init(this)之前,我嘗試了Thread.setDefaultUncaughtExceptionHandle;這對我有效。感謝您的幫助 – akk

相關問題