私はいくつかのAndroidアプリケーションを作成しましたが、いくつかのテストを行っているとクラッシュします。
しかし、クラッシュの理由がわからないので、クラッシュの理由をファイルに保存して、後でそれを確認できるようにする必要があります。アプリケーションの実行中にPCに接続しないため、保存するための提案が必要です。クラッシュの理由..?
以下のようにしてください。
try{
//your code which throws exception
}
catch(Exception e){
e.printStackTrace(); //optional
//save your exception in a text file on sd-card
}
後でテキストファイルを読んで、例外を知ることができます
私がこれまでに出くわした最良の方法は、インターネット許可を追加し、ACRAを使用することです。ACRAを使用すると、レポートをGoogle Docsスプレッドシートに送信でき、テストと本番環境で機能します。
ACRA以外に、2つのオプションがあります。
try catch
ブロックで囲み、データをどこかに保存します。詳細が限られていることをお詫びしますが、Androidにはすでにロギングのオプションがありませんか?
http://developer.android.com/reference/android/util/Log.html
私はこれを試したことがなく、おそらくtry、catchの答えを選択するでしょうが、これは単なる別のオプションです。
trycatchブロックを実行できます。
try {
//the code lies here
} catch(Exception e) {
//here you can save the e.toString() to a FileOutputStream and then save the file
}
アプリケーションクラスを使用して「setDefaultUncaughtExceptionHandler」を設定する必要があります
public class YourApplication extends Application {
private Thread.UncaughtExceptionHandler defaultUEH;
// handler listener
private Thread.UncaughtExceptionHandler _unCaughtExceptionHandler =
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
// here I do logging of exception to a db
PendingIntent myActivity = PendingIntent.getActivity(getApplicationContext(),
192837, new Intent(getApplicationContext(), YourActivity.class),
PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager;
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
15000, myActivity);
System.exit(2);
// re-throw critical exception further to the os (important)
defaultUEH.uncaughtException(thread, ex);
}
};
public YourApplication() {
defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
// setup handler for uncaught exception
Thread.setDefaultUncaughtExceptionHandler(_unCaughtExceptionHandler);
}
}
Androidマニフェストのアプリケーションタグにタグ名="your.app.application.YourApplication"を設定します