2013-02-23 50 views
3

出於測試目的,我在我的MainActivity的onCreate()方法中創建了一個錯誤。 Acra認識到並顯示吐司。Acra在MainActivity的onCreate()中無法正常工作?

02-23 19:05:35.075: E/ACRA(599): ACRA caught a RuntimeException exception for .... Building report. 
02-23 19:05:35.080: I/ACRA(599): READ_LOGS granted! ACRA can include LogCat and DropBox data. 
02-23 19:05:35.080: D/ACRA(599): Writing crash report file 1361642735000.stacktrace. 
02-23 19:05:35.125: D/ACRA(599): Waiting for Toast + worker... 
02-23 19:05:35.125: D/dalvikvm(599): GC_CONCURRENT freed 278K, 18% free 2512K/3032K, paused 2ms+4ms, total 29ms 
02-23 19:05:38.160: D/ACRA(599): About to create DIALOG from #handleException 
02-23 19:05:38.160: D/ACRA(599): Creating Dialog for 1361642735000.stacktrace 
02-23 19:05:38.170: D/ACRA(599): Wait for Toast + worker ended. Kill Application ? true 
02-23 19:05:38.190: E/ACRA(599): ... fatal error : Unable to start activity ComponentInfo{.../....MainActivity}: java.lang.ArithmeticException: divide by zero 

但這一切連連不休發生後... 敬酒再次出現,我看再stackstrce ...

當我創建的,可以說,onOptionsItemSelected()的錯誤,一切按預期工作。出現Toast。我的應用程序關閉。出現對話框。這就是我想要的...

但爲什麼這不適用於onCreate()正確?

Acra庫(版本4.4.0)位於libs文件夾中。

MainActivity:

import org.acra.ACRA; 
import org.acra.annotation.*; 
import org.acra.ReportingInteractionMode; 

import android.app.Application; 

@ReportsCrashes(formKey = "", 
     mailTo = "my_email_address", 
     mode = ReportingInteractionMode.DIALOG, 
     resToastText = R.string.crash_toast_text, 
     resDialogText = R.string.crash_dialog_text, 
     resDialogIcon = android.R.drawable.ic_dialog_info, 
     resDialogTitle = R.string.crash_dialog_title, 
     resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, 
     resDialogOkToast = R.string.crash_dialog_ok_toast 
     ) 

public class MyApplication extends Application { 

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

} 

清單:

<application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/Theme.Sherlock.Light.DarkActionBar" 
     android:allowBackup="true" 
     android:name="MyApplication" > 

     <activity android:name="org.acra.CrashReportDialog" 
      android:theme="@android:style/Theme.Dialog" 
      android:launchMode="singleInstance" 
      android:excludeFromRecents="true" 
      android:finishOnTaskLaunch="true" /> 

我的MainActivity看起來是這樣的:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    int i = 1/0; // raise an error for acra 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mHandler.postDelayed(mUpdateTimeTask, 0); 
} 

了Runnable:

private Runnable mUpdateTimeTask = new Runnable() { 
    public void run() { 

     // doing stuff here... 

     mHandler.postDelayed(mUpdateTimeTask, 1000); 
    } 
}; 
+0

發佈MainActivity的onCreate(),它*看起來像*您的活動正在重新啓動。 – 2013-02-23 18:39:00

+0

我以爲我的應用程序在以前發生錯誤時不會啓動Runnable?我怎樣才能防止呢? – Oliver 2013-02-23 18:51:50

+0

@Oliver:你能夠成功地調出對話框。就我而言,ACRA未能提出對話。 – VendettaDroid 2013-04-09 18:32:05

回答