【问题标题】:Acra not working properly in onCreate() of the MainActivity?Acra 在 MainActivity 的 onCreate() 中无法正常工作?
【发布时间】:2013-02-23 18:31:04
【问题描述】:

出于测试目的,我在 MainActivity 的 onCreate() 方法中创建了一个错误。 Acra 认出了这一点并展示了一个 Toast。

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

但在那之后,一切都无休止地一次又一次地发生...... Toast 又出现了,我又看到了 stackstrce...

当我在其中创建错误时,比如说 onOptionsItemSelected(),一切都按预期工作。吐司出现。我的应用程序关闭。出现对话框。这就是我想要的...

但是为什么这在 onCreate() 中不能正常工作呢?

Acra 库(4.4.0 版)位于 libs 文件夹中。

主活动:

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);
    }
};

【问题讨论】:

  • 发布 MainActivity 的 onCreate(),它似乎你的 Activity 正在重新启动。
  • 我以为我的App在之前发生错误时不会启动Runnable?我怎样才能防止这种情况发生?
  • @Oliver:你能成功调出对话框吗?在我的情况下,ACRA 无法弹出对话框。

标签: java android acra


【解决方案1】:

所以这种行为似乎是一个 Acra 错误,将在 4.5 版中得到修复 -> https://github.com/ACRA/acra/issues/42

【讨论】:

  • 您能否成功调出对话框。在我的情况下,ACRA 无法弹出对话框。我正在使用 4.5 ACRA。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多