【问题标题】:Count android crashes计算 android 崩溃
【发布时间】:2015-04-30 01:38:41
【问题描述】:

我需要计算我的应用程序在我的设备上发生了多少次崩溃。我怎样才能做到这一点?在哪里存储这个计数?我需要创建一些有许多崩溃的字段。每次崩溃后,我都应该增加这个数字。

【问题讨论】:

  • 这是一个更好的主意:修复错误,使其不会崩溃...
  • 为什么要构建崩溃的应用程序?
  • 您可以使用Crashlytics 跟踪崩溃情况

标签: android logging


【解决方案1】:

在应用程序的第一个 onCreate 中启动以下代码: 将 int 保存到 SharedPreferences 中的文件中。每次此代码命中时将其加一。

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(final Thread thread, final Throwable ex) {
                ex.printStackTrace();
                //increase int here
                final StringWriter sw = new StringWriter();
                final PrintWriter pw = new PrintWriter(sw);
                ex.printStackTrace(pw);
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/html");
                intent.putExtra(Intent.EXTRA_EMAIL, "");
                intent.putExtra(Intent.EXTRA_SUBJECT, "My App is on fire!");
                intent.putExtra(Intent.EXTRA_TEXT, sw.toString());
                startActivity(Intent.createChooser(intent, "Send Crash Log"));
                Variables.activity.finish();
                System.exit(0);

            }
        });

这将达到您的目的,甚至可以要求他们通过电子邮件将崩溃日志发送给您。你不应该有任何已知的错误或任何需要增加计数器。这是一个坏主意。但我还是提供了代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 2014-12-27
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多