当返回到应用程序的静态变量空变量、静态、应用程序

2023-09-12 00:16:41 作者:烈性痞子

在我的应用程序有是一个的被设置为空,当我回到我的应用程序从外部浏览器的静态变量。好像应用程序或外部网页,我发起复杂够了一些部分被杀害。

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.

如果应用程序要完全杀死,然后从将是确定的主要活动relauched,但重新开张是从启动浏览器的活动 - 这并不意味着设置应用程序状态,所以它的访问时崩溃空静态变量。这是一出的六个设备问题对我来说,所以我需要一些建议。

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.

有一个标志设置为prevent这种行为?

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: How do I save an Android application's state?

请注意,这是事实的不可以一外的六个设备故障。这是一个关于所有设备的问题,它只是在你的设备的一个更加明显,可能是因为它有较少的内存。如果你对你的任何设备上运行一个非常内存密集型应用程序,你应该看到相同的行为。也没有标志,以prevent这一点。这是标准和预期。

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.