0

Ich habe versucht, einen benutzerdefinierten UncaughtExceptionHandler in meine Anwendung zu implementieren, und ich habe die Bibliothek Ereza/CustomActivityOnCrash entdeckt.Ereza CustomActivityOnCrash startActivity with Intent

Ich habe den gesamten Code wie in der README (https://github.com/Ereza/CustomActivityOnCrash) beschrieben hinzugefügt, aber ich kann immer noch nicht scheinen, um es zum Laufen zu bringen. Wenn ich meine App zum Absturz zwinge, erscheint ein weißer Bildschirm und verschwindet sofort.

Irgendwelche Ideen, was könnte dies verursachen? unten ist einige meiner Code

AndroidManifest

<activity 
     android:name="com.test.SplashActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:theme="@style/AppTheme"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.test.MainActivity" 
     android:label="MainActivity" 
     android:screenOrientation="portrait" 
     android:theme="@style/AppTheme" 
     android:windowSoftInputMode="adjustPan"> 
     <intent-filter> 
      <action android:name="cat.ereza.customactivityoncrash.RESTART" /> 
     </intent-filter> 
    </activity> 

    <activity 
     android:name="com.test.ErrorActivity" 
     android:label="Error" 
     android:screenOrientation="portrait" 
     android:theme="@style/AppTheme" 
     android:windowSoftInputMode="adjustPan"> 
     <intent-filter> 
      <action android:name="cat.ereza.customactivityoncrash.ERROR" /> 
     </intent-filter> 
    </activity> 

Anwendungsklasse

public class TestApplication extends Application { 

    private static TestApplication mInstance; 
    private TimeZone usersDefaultTimeZone; 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     mInstance = this; 

     //Customization for CustomActivityOnCrash 
     //Show (TRUE) or Hide (FALSE) the stack trace on the error activity 
     CustomActivityOnCrash.setShowErrorDetails(false); 

     //Enable Restart (TRUE) 'Restart App' button 
     //Disable Restart (FALSE) 'Close App' button 
     CustomActivityOnCrash.setEnableAppRestart(true); 

     //This sets a custom error activity class instead of the default one. 
     CustomActivityOnCrash.setErrorActivityClass(ErrorActivity.class); 

     //This sets a EventListener to be notified of events regarding the error activity, 
     //CustomActivityOnCrash.setEventListener(new CustomEventListener()); 

     //Specify the Activity to to restart the application 
     CustomActivityOnCrash.setRestartActivityClass(MainActivity.class); 

     //Install CustomActivityOnCrash 
     CustomActivityOnCrash.install(this); 

     //Now initialize your error handlers as normal 
     Fabric.with(this, new Crashlytics()); 
    } 

    public static synchronized TestApplication getInstance() { 
     return mInstance; 
    } 

    static class CustomEventListener implements CustomActivityOnCrash.EventListener{ 

     @Override 
     public void onLaunchErrorActivity() { 
      Log.i("BookingApp", "onLaunchErrorActivity()"); 
      Crashlytics.logException(new Exception("Unknown Exception Caught & Error screen displayed to user")); 
     } 

     @Override 
     public void onRestartAppFromErrorActivity() { 
      Log.i("BookingApp", "onRestartAppFromErrorActivity()"); 
      Answers.getInstance().logCustom(new CustomEvent("Restart After Crash")); 
     } 

     @Override 
     public void onCloseAppFromErrorActivity() { 
      Log.i("BookingApp", "onCloseAppFromErrorActivity()"); 
      Answers.getInstance().logCustom(new CustomEvent("Close After Crash")); 
     } 
    } 
} 
+0

geben Sie bitte logcat –

Antwort

1

Hallo setzen in Anwendungsklasse folgenden Code und ändern, wie Sie für handeling nicht behandelte Ausnahmen wollen:

@Override 
    public void onCreate() { 
     super.onCreate(); 
     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 


//Work what you want to do.... 

//start new activity with clearing task 
Intent intent = new Intent(this, ActivityClass.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     startActivity(intent); 

//end 
      System.exit(2); // kill off the crashed app 
     } 

Hoffe, diese Hilfe, die ich in meiner App verwende ... funktioniert.

+0

Hallo Ramesh, Yup das ist eine gute Lösung, aber ich wollte den Fehler zu Crashlytics anmelden und starten Sie die Anwendung auch – RheeBee

+0

Ja ich die Antwort für Start-Aktivität mit klaren vorherigen Aufgabe bin zu aktualisieren .. Sie kann dies als Antwort akzeptieren .. –

0

Nach einigen weiteren Untersuchungen entdeckte ich, dass diese Bibliothek/Code nicht gerne im Debug-Modus ausgeführt wird. Wenn ich die Anwendung auf meinem Gerät installiert und von dort gestartet habe (anstatt Debug von Android Studio zu verwenden), schien es gut zu funktionieren.

0

Dies wird höchstwahrscheinlich dadurch verursacht, dass ErrorActivity nicht als Teil eines anderen Prozesses angegeben wird.

Von der Bibliothek Dokumentation in Bezug auf die Verwendung einer Aktivität benutzerdefinierten Fehler:

Wenn Sie diese verwenden, muss die Aktivität in Ihrem AndroidManifest.xml, zu :error_activity mit process Satz deklariert werden.

Verwandte Themen