是静态安全的机器人? [英] Is the static safe in Android?

查看:131
本文介绍了是静态安全的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在code,它定义了一个静态字段,我活动的onStop / ONSTART调用之间重用使用一个静态类。这里有一个场景:

I use a single static class in my code that defines a static field which I'm reusing between Activity onStop/onStart invocations. Here's a scenario:

  1. 在用户点击授权按钮(静态数据初始化)
  2. 在活动停止,网页浏览器被称为
  3. 在浏览器中执行回调活性得以恢复(静态数据重复使用)

至少有一个我的用户报告故障,在第3步,我无法重现,但它看起来像的静态数据重置

At least one of my users reports the failure at step 3 which I cannot reproduce but which looks like reset of static data

有什么建议?

推荐答案

这是不安全的。你的过程的onStop和ONSTART之间被杀死,因此,所有静态数据将不复存在。事实上之前它到达的on​​Stop你的活动,甚至可以杀死。在您的测试过程中没有被打死,但它的用户。请参阅的Andr​​oid活动的生命周期它有一个很好的流程图示出准备。

That is not safe. Your process can be killed between onStop and onStart, so all static data will be gone. In fact your activity can even be killed before it gets to onStop. In your tests the process was not killed, but it was for the user. See the Android activity life cycle which has a nice flow chart showing the possibilities.

您需要存储数据的其他方式,在preFS或数据库为例。

You need to store the data some other way, in prefs or database for example.

这篇关于是静态安全的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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