Java – why does Android App automatically restart after running abnormally?
My application runs on two 5.0 Android systems
In my development, I have an uncapped runtimeException
In case of exceptions, my application will restart automatically,
I don't know why my application will restart automatically? Even if I call system. Exit (1)
This is a log with runtimexception
E/AndroidRuntime(23905): FATAL EXCEPTION: main
E/AndroidRuntime(23905): Process: com.oosmart.mainapp, PID: 23905
E/AndroidRuntime(23905): android.database.sqlite.sqliteException: no such table: devices (code 1): , while compiling: drop table devices
E/AndroidRuntime(23905): at android.database.sqlite.sqliteConnection.nativePrepareStatement(Native Method)
E/AndroidRuntime(23905): at android.database.sqlite.sqliteConnection.acquirePreparedStatement(sqliteConnection.java:889)
E/AndroidRuntime(23905): at android.database.sqlite.sqliteConnection.prepare(sqliteConnection.java:500)
E/AndroidRuntime(23905): at android.database.sqlite.sqliteSession.prepare(sqliteSession.java:588)
E/AndroidRuntime(23905): at android.database.sqlite.sqliteProgram.<init>(sqliteProgram.java:58)
E/AndroidRuntime(23905): at android.database.sqlite.sqliteStatement.<init>(sqliteStatement.java:31)
E/AndroidRuntime(23905): at android.database.sqlite.sqliteDatabase.executesql(sqliteDatabase.java:1674)
E/AndroidRuntime(23905): at android.database.sqlite.sqliteDatabase.execsql(sqliteDatabase.java:1655)
E/AndroidRuntime(23905): at com.oosmart.mainaplication.db.DBOperation.execute(DBOperation.java:81)
E/AndroidRuntime(23905): at com.oosmart.mainaplication.db.DevicesDB.dropTable(DevicesDB.java:154)
E/AndroidRuntime(23905): at com.oosmart.mainaplication.db.DBHelper.DropTable(DBHelper.java:30)
E/AndroidRuntime(23905): at com.oosmart.mainaplication.fragment.UserCenterFragment.onExitClick(UserCenterFragment.java:128)
E/AndroidRuntime(23905): at com.oosmart.mainaplication.fragment.UserCenterFragment$$ViewBinder$6.doClick(UserCenterFragment$$ViewBinder.java:74)
E/AndroidRuntime(23905): at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
E/AndroidRuntime(23905): at android.view.View.performClick(View.java:4806)
E/AndroidRuntime(23905): at android.view.View$PerformClick.run(View.java:19952)
E/AndroidRuntime(23905): at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(23905): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(23905): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(23905): at android.app.ActivityThread.main(ActivityThread.java:5313)
E/AndroidRuntime(23905): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(23905): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(23905): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1116)
E/AndroidRuntime(23905): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:809)
This is the log of system.exit
I/AndroidRuntime(20479): VM exiting with result code 1, cleanup skipped.
I/AndroidRuntime(23172): VM exiting with result code 1, cleanup skipped.
I/Process (24461): java.lang.RuntimeException
Grep logs I use at runtime
Update: even if I call Android. OS. Process. Killprocess (Android. OS. Process. Mypid());
The application is still restarted with the new PID. I don't know why I can't exit the code completely
resolvent:
It may be because you did not complete the previous activity, and when the new activity creates an exception, it closes the current activity and opens the previous activity, and the runtime exception crashes, causing your application to crash, and you try to delete even nonexistent tables, or even the system. Exit() Will not exit your application. The best practice is to try to capture when using any complex coding. If I am wrong, someone will correct me