返回应用程序时的静态变量 null [英] static variable null when returning to the app

查看:19
本文介绍了返回应用程序时的静态变量 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中有一个静态变量,当我从外部浏览器返回到我的应用程序时,该变量被设置为 null.如果我启动的外部网页足够复杂,应用程序或其某些部分似乎会被杀死.

In my app there's a static variable that's being set to null when I return to my app from the external browser. Seems like the app or some portion of it is killed if the external web page I'm launching is complex enough.

如果应用程序被完全杀死,然后从主要活动中重新启动,那是可以的,但重新启动是从启动浏览器的活动中进行的 - 这并不意味着设置应用程序状态,因此它在访问时崩溃空静态变量.这对我来说是六分之一的设备问题,所以我需要一些建议.

If the app were to be killed entirely and then relauched from the main activity that would be ok, but the relaunch is from the activity that started the browser - and it's not meant to set the app state so it's crashing when accessing the null static variable. This is a one-out-of-six device problem for me so I need some advice.

有没有设置标志来防止这种行为?

Is there a flag to set to prevent this behavior?

推荐答案

这是大多数移动操作系统(当然包括 Android)中的标准行为.如果其他具有更高优先级的应用程序(通常,如果它在前台,它的优先级更高)需要资源,则您的应用实际上经常被杀死.这是因为移动设备的资源相对有限.

This is standard behavior in most mobile operating systems, definitely including Android. Your app is in fact very often killed if some other application with higher priority (generally, if it's in the foreground it's higher priority) needs the resources. This is due to the nature of mobile devices having relatively limited resources.

您应该将数据保存在更持久的地方.您可能会发现这篇关于一般数据存储的文章很有用.这个问题也应该是相关的:使用保存实例状态保存 Android 活动状态

You should save your data somewhere more durable. You might find this article on general Data Storage to be useful. This question should be relevant too: Saving Android Activity state using Save Instance State

请注意,这实际上不是一个六分之一的设备问题.这是所有设备上的问题",在您的其中一台设备上更明显,可能是因为它的内存较少.如果您在任何其他设备上运行内存密集型应用程序,您应该会看到相同的行为.也没有标志可以防止这种情况.这是标准的和预期的.

Note that this is in fact not a one-out-of-six device problem. This is a "problem" on all devices, it's just more apparent on one of your devices probably because it has less memory. If you run a very memory-intensive app on any of your other devices you should see the same behavior. Also there is no flag to prevent this. This is standard and expected.

这篇关于返回应用程序时的静态变量 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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