模拟在模拟器中杀死活动 [英] Simulate killing of activity in emulator

查看:26
本文介绍了模拟在模拟器中杀死活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在模拟器上为我的应用测试 onSaveInstanceStateonRestoreInstanceState.

I would like to test out onSaveInstanceState and onRestoreInstanceState for my app on the emulator.

我发现了这个,它说我们可以在方向更改期间模拟这一点,但我将一些变量存储在应用程序级别(子类 android.app.Application),因此方向更改不会消除变量.

I have found this, which says that we could simulate this during orientation change, but I'm storing some of my variables on the application level (subclass android.app.Application), so the orientation change does not wipe out the variables.

所以我的问题是,我怎样才能模拟低内存情况从而杀死我的活动?

So my question is, how can I simulate the low memory situation thus killing of my activities?

希望我已经说清楚了.谢谢

Hope I've made myself clear. Thanks

推荐答案

您可以暂停您的应用程序(通过按下主页按钮、模拟呼叫等).然后通过 adb 杀死应用程序的进程.由于文档说在 onPause() 返回后,您的应用程序可以在没有任何进一步通知的情况下被终止,因此这是一个公平的测试.

You can pause your application (by pushing the Home button, simulating a call, whatever). Then kill the app's process through adb. Since the docs say that after onPause() returns your app can be killed without any further notice, this is a fair test.

如果您不想费心查找应用进程的 pid,可以使用 adb shell am kill com.example.package_name 来终止应用进程.确保应用程序置于后台.文档说这个命令只杀死可以安全杀死并且不会影响用户体验的进程."因此,您可能需要先启动几个其他应用,然后再尝试此应用.

If you don't want to go through the trouble of finding the pid of your app's process, you can use adb shell am kill com.example.package_name to kill your app's process. Make sure that the app is put in the background. The docs say that this command "kills only processes that are safe to kill and that will not impact the user experience." So you might want to launch a couple of other apps before trying this one.

这篇关于模拟在模拟器中杀死活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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