问题
I have my AppMain
class [My class Name] that extended the Application
class in my app. That have some Globals.
I have mentioned inside the manifest. and my app running normal. I have exit button in my app to quit it using System.exit(0);
.
After that when I start my app using Recent Apps option, it just crashed. ( FYI. Hold down the Home key and the recent apps will appear)
Starting the app from Apps List it is fine.
How can I fix this?
Here part of my manifest:
<application
android:name=".activity.MainApp"
android:debuggable="false"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
Edit:
Crash Log:
04-16 19:04:59.416: E/AndroidRuntime(19649): FATAL EXCEPTION: main
04-16 19:04:59.416: E/AndroidRuntime(19649): java.lang.RuntimeException: Unable to resume activity {xxx.xxx.xxx..HomeActvity}: java.lang.NullPointerException
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3128)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.os.Looper.loop(Looper.java:123)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-16 19:04:59.416: E/AndroidRuntime(19649): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 19:04:59.416: E/AndroidRuntime(19649): at java.lang.reflect.Method.invoke(Method.java:521)
04-16 19:04:59.416: E/AndroidRuntime(19649): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-16 19:04:59.416: E/AndroidRuntime(19649): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-16 19:04:59.416: E/AndroidRuntime(19649): at dalvik.system.NativeStart.main(Native Method)
04-16 19:04:59.416: E/AndroidRuntime(19649): Caused by: java.lang.NullPointerException
04-16 19:04:59.416: E/AndroidRuntime(19649): at com.xxx.xxxx.xxx.DatabaseManager.selectFieldsFrom(DatabaseManager.java:161)
04-16 19:04:59.416: E/AndroidRuntime(19649): at com.xxx.xxxx.xxx.DBUtils.retrieveFromStore(DBUtils.java:75)
04-16 19:04:59.416: E/AndroidRuntime(19649): at com.xxx.xxxx.xxx.DBController.getAllWishList(DBController.java:407)
04-16 19:04:59.416: E/AndroidRuntime(19649): at xxx.xxxx.xxx.HomeActvity.retrieveFromListTable(HomeActvity.java:441)
04-16 19:04:59.416: E/AndroidRuntime(19649): at xxx.xxxx.xxx.HomeActvity.onResume(HomeActvity.java:642)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.Activity.performResume(Activity.java:3823)
04-16 19:04:59.416: E/AndroidRuntime(19649): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
04-16 19:04:59.416: E/AndroidRuntime(19649): ... 12 more
This is because the app not starting from splash when starting from recent apps.DB is released on System.exit(0);
so showing null Pointer Exception.
UPDATE:
The app force closed because I set the splash screen and Home screen activity properties to Single Task
. After removing this it working fine.
回答1:
The app isn't actually running if it isn't consuming processor time (either running a service or presenting an Activity
to the user). It may be in memory but Android's memory management model is designed that way and the app will be killed if something else needs the memory. onPause
is a good indication that you may soon exit, and onDestroy
should free up any resources that an exit button would.
If you absolutely must exit, you can use finish()
instead, and/or try using the excludeFromRecents
or noHistory
flags in the manifest to avoid the crash. There should be a few others you can play around with, too.
See this question and the Process Lifecycle section of the developer docs.
来源:https://stackoverflow.com/questions/10174892/extended-application-class-force-close-on-restart-android