扩展应用程序类-在重新启动Android时强制关闭 [英] Extended Application class - Force Close on Restart Android

查看:120
本文介绍了扩展应用程序类-在重新启动Android时强制关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的AppMain类[我的类名称],该类在我的应用程序中扩展了Application类.那有一些Globals. 我已经在清单中提到过.并且我的应用正常运行.我的应用程序中有退出按钮,可以使用System.exit(0);退出它.

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); .

在那之后,当我使用 Recent Apps 选项启动我的应用程序时,它刚刚崩溃了. (仅供参考.按住Home键,将显示最新的应用程序)

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)

应用列表启动应用即可.

我该如何解决?

这是我的清单的一部分:

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" >

崩溃日志:

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

这是因为从最近的应用程序启动时,该应用程序不是从启动启动.DB已在System.exit(0);上发布,因此显示了空的指针异常.

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.

更新:

由于我将启动屏幕和主屏幕活动属性设置为Single Task,因此应用程序强制关闭.删除后,它可以正常工作.

The app force closed because I set the splash screen and Home screen activity properties to Single Task . After removing this it working fine.

推荐答案

如果该应用程序不消耗处理器时间(运行服务或向用户显示Activity),则该应用程序实际上并未运行.它可能在内存中,但是Android的内存管理模型是按这种方式设计的,如果其他需要内存的应用程序将被杀死. onPause很好地表明您可能会很快退出,并且onDestroy应该释放退出按钮会释放的所有资源.

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.

如果绝对必须退出,则可以改用finish()和/或尝试在清单中使用excludeFromRecentsnoHistory标志,以避免崩溃.您应该也可以玩一些其他游戏.

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.

请参见此问题.

这篇关于扩展应用程序类-在重新启动Android时强制关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆