Android:当应用程序由于内存限制而超出堆栈时应用程序的状态
请帮我解决这个问题。
1 > I am having application which Uses Service to retrieve data from server.
2 > Now on Pressing Home key and i have opened new application..
3 > I have opened around 20 application.
4 > So my application might go out of memory stack.
5 > now i am resuming my application, application crashes as i am opening activity of my
application which is not in the stack.
无论如何,我是否可以处理此异常并将我的活动重定向到主页或重新启动应用程序简历并且不在堆栈中...
Please help me to resolve this problem.
1 > I am having application which Uses Service to retrieve data from server.
2 > Now on Pressing Home key and i have opened new application..
3 > I have opened around 20 application.
4 > So my application might go out of memory stack.
5 > now i am resuming my application, application crashes as i am opening activity of my
application which is not in the stack.
Is there anyway by which i can handle this exception and redirect my activity to Homepage or relaunch application resume and is not in stack...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这确实是一个非常好的问题,我试图自己去解答。
我什至想知道杀死应用程序和重新启动手机有什么区别。
如果用户手动终止某个应用程序或打开其他 20 个应用程序,他可能希望该应用程序从头开始启动。
为什么 Android 在手机重启后无法恢复状态?
另外,我发现当应用程序(被系统)终止时,全局变量在活动重新启动时变为空。
这就打破了Java的概念。如果应用程序中有某种状态并且应用程序删除了它,我希望应用程序重新启动。
我提出的解决方案:
第一点的缺点是需要在每个Activity上进行状态问题处理(Android中还没有实现AOP)。
希望有帮助。
Indeed a very good question which I try to puzzle out myself.
I even wonder What's the difference between killing an app and restarting the phone.
If a user manually kills an app or opens 20 other apps, he'd probably want the app to start from the beginning.
Why Android aren't restoring state after phone restart?
Also, I see that when an app is killed (by the system), global variables turn to null upon activity reinitiating.
This kind of breaks the concept of Java. If you have some kind of state in the application and the application erases it, I would expect the application to restart.
The solution I propose:
The downside of the first point is that the state problem handling needs to be done on every Activity (AOP is not yet implemented in Android).
Hope that helped.
使用 SharedPreferences 保存应用程序状态
Use SharedPreferences for save Application state