Java 什么能让android应用程序在捕获所有异常时退出/崩溃

Java 什么能让android应用程序在捕获所有异常时退出/崩溃,java,android,exception,crash,Java,Android,Exception,Crash,我确实在我的android应用程序中捕获了所有未处理的异常,就像常见的方式一样: public class AppContext extends Application{ public static Context context; public void onCreate(){ super.onCreate(); AppContext.context = getApplicationContext(); // Setup h

我确实在我的android应用程序中捕获了所有未处理的异常,就像常见的方式一样:

public class AppContext extends Application{

    public static Context context;

    public void onCreate(){
        super.onCreate();

        AppContext.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)
    {
      Intent intent = new Intent (context, Login.class);
      intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
      startActivity (intent);

      System.exit(1);
    }
} 
但尽管如此,该应用程序有时(偶尔)会在没有任何通知的情况下退出,并且日志中没有提供任何崩溃消息,我不知道除了异常之外还有什么其他原因会导致这种情况

该应用程序设计为始终运行,无论发生什么都不会退出,这使我能够像过去一样处理所有未捕获的异常

值得一提的是,我在LogCat中收到了一些
System.Err
消息(不知道它是否有用,也不知道我是否在应用程序退出时收到它,甚至不知道我是否从应用程序中得到它,因为LogCat没有提到这一点):

1:

Window type can not be changed after the window is added; ignoring change of com.android.internal.policy.impl.PhoneWindow$DecorView{426c3e00 V.E..... R.....ID 0,0-0,0}
java.lang.SecurityException: WifiService: Neither user 10086 nor current process has android.permission.CHANGE_WIFI_STATE.
2:

Window type can not be changed after the window is added; ignoring change of com.android.internal.policy.impl.PhoneWindow$DecorView{426c3e00 V.E..... R.....ID 0,0-0,0}
java.lang.SecurityException: WifiService: Neither user 10086 nor current process has android.permission.CHANGE_WIFI_STATE.

为什么不先添加android.permission。将WIFI状态更改为你的清单?@Kim,他好像在尝试自动重启应用程序。它只是因为你正在调用
system.exit()
而退出。@StephenC,似乎他正在尝试制作某种“信息亭”,它不应该崩溃/应该在崩溃时自动重启。