이 그냥 MainActivity
이 crash
라는 boolean
변수를 생성에 응용 프로그램을 입력하고 false
의 값으로 SharedPreferences
에 저장할 때 우선, SharedPreferences
을 통해 일어날 것, 바로이 다시 저장 변수 값이 true
이고 이는 자동으로 이전에 저장된 crash
값보다 우선합니다.
private void loadSavedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
boolean crash = sharedPreferences.getBoolean("crash", false);
if(crash){
// then your app crashed the last time
}else{
// then your app worked perfectly the last time
}
}
그래서, 당신의 충돌 핸들러 클래스에서, 단지 true로 값을 저장 :
private void savePreferences(String key, String value) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
Editor editor = sharedPreferences.edit();
editor.putBoolean("crash", false);
editor.commit();
}
가 저장된 값을로드하려면 :
는 값을 저장하려면
ps 이것은 OS의 앱에서 처리되지 않은 모든 예외에 대해 실행되어야합니다. 안드로이드 죽이고 당신의 응용 프로그램을 다시 시작하면, 정적 변수가 null로 설정
public class CrashHandler extends Application{
public static Context context;
public void onCreate(){
super.onCreate();
CrashHandler.context = getApplicationContext();
// Setup handler for uncaught exceptions.
Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException (Thread thread, Throwable e)
{
handleUncaughtException (thread, e);
}
});
}
public void handleUncaughtException (Thread thread, Throwable e)
{
e.printStackTrace(); // not all Android versions will print the stack trace automatically
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
Editor editor = sharedPreferences.edit();
editor.putBoolean("crash", true);
editor.commit();
}
}
아래에 주어진하지 않을 경우 [이 질문] (HTTP를 살펴 보자 말할 것이다 변수를 얻을 수있는 공유 환경 설정의 도움으로
.com/questions/601503/how-do-i-get-crash-data-from-my-android 응용 프로그램), 이렇게하면 좋을 것 같습니다. –
@G_V 그걸 들여다 보았지만 외장 라이브러리에이 보고서를 더하면 메모리 충돌 등의 OS 관련 충돌이 발생하지 않을 것입니다. –
응용 프로그램에 알아 차리지 못했기 때문에 이전에 발생한 시스템 충돌을 감지하도록 요청할 수 없습니다 그것. 방금 OS/커널에 의해 죽었습니다. 당신이 묻는 것은 적어도 AFAIK는 불가능합니다. – shkschneider