如何模拟杀伤活性,以节约内存? [英] How to simulate killing activity to conserve memory?

查看:132
本文介绍了如何模拟杀伤活性,以节约内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的DOC说:当系统,而不是用户,关闭一个活动,以节省内存,... 但如何来模拟这种情况呢?我想调试onRestoreInstanceState方法,但不知道怎么样。 任何意见是AP preciated! 谢谢!

L.J.W

解决方案

您不能做,在一个自动化的方式B / C的完全不确定性。

请参阅我的答案在这里: http://stackoverflow.com/a/15048112/909956 了解详细信息

不过,好消息是,所有你需要做的只是模拟的onSaveInstanceState打电话,你是间接测试此内存不足的情况​​。

的onSaveInstanceState可以通过触发:

  1. 在失去焦点(由pressing家这在本质上就像是从你的应用程序切换到发射器的应用程序),启动另一个活动,pressing最近通话
  2. 改变方向。这是更简单的方法,如果您使用的是仿真器
  3. 在改变开发商设置:转到开发人员选项 - >应用程序 - >不保留活动。这是,如果你暂时在实际设备上测试的最佳选择。

Android doc say:"When the system, rather than the user, shuts down an activity to conserve memory, ... " But how to simulate this situation?I want to debug the onRestoreInstanceState method,but don't know how to. Any advice is appreciated! Thanks!

L.J.W

解决方案

You can't do it in an automated way b/c its completely non deterministic.

See my answer here: http://stackoverflow.com/a/15048112/909956 for details.

But good news is that all you need to do is just simulate calling onSaveInstanceState and you are indirectly testing this low memory situation.

onSaveInstanceState can be triggered by:

  1. losing focus (by pressing home which in essence is like switching from your app to launcher app), launching another activity, pressing recents
  2. changing orientation. this is the easier way if you are using an emulator
  3. changing developer setting: goto developer options --> Apps --> Don't keep activities. This is best option if you are testing temporarily on an actual device.

这篇关于如何模拟杀伤活性,以节约内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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