2016-09-05 74 views
0

我有一個類A擴展Application.In A處理uncaughtexceptions。現在的問題是,每當應用程序遇到的任何問題,應用程序凍結和崩潰從應用程序類別退出應用程序

public class A extends Application { 
    @Override 
    public void onCreate() { 
    super.onCreate(); 
    final AppContext context = AppContext.getInstance(); 
    context.setContext(this); 
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { 
     @Override 
     public void uncaughtException(Thread thread, Throwable e) { 
      mContext = context.getContext(); 
      e.getCause().getMessage(); 
      AppPreference.getInstance().setCrashReason(e.getMessage()); 
      Intent intent = new Intent(); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity (intent); 
      System.exit(1); 
     } 
    }); 
} 

我尋覓了很多,但都走了進去vain.Thanks提前之前出現黑屏。

回答

0

您可以使用以下方法:

public class MyApplication extends Application 
{ 
    public void onCreate() 
    { 
    // 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 

     Intent intent = new Intent(); 
     ntent.setAction ("com.mydomain.SEND_LOG"); // see step 5. 
     intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application 
     startActivity (intent); 
    } 
} 

根據本answer

+0

這是我在做什麼正確的now.App獲得凍結和黑色的屏幕變成up.After一會兒應用程序沒有響應警報過來。 –

+0

@ashlok malik檢查提供的完整答案鏈接。 – Stanojkovic

+0

我已經提到了上面提到的鏈接,但是應用程序仍然處於凍結狀態,只要遇到任何錯誤就會顯示黑屏 –