如何仿效Android操作系统后台应用程序的卸载? [英] How to emulate unloading of a background application by Android OS?

查看:203
本文介绍了如何仿效Android操作系统后台应用程序的卸载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试目的,我需要能够轻松重现的情况时,Android系统决定保存的状态并杀死后台应用,因为它一般不会内存优化的目的相同。其实,我也需要测试这样一个去除工艺的恢复过程中,当用户切换回吧。

在straighforward方法是打开应用程序,然后打开多个其他任务尝试分配尽可能多的资源成为可能。这是过于复杂和不可靠的。

我发现<一href="http://stackoverflow.com/questions/5075773/how-to-emulate-the-process-of-a-background-activity-is-killed-by-the-system-beca">this问题的SO ,但得到的答复意味着简单地杀死进程,这似乎不是一个等价的,因为似乎没有办法进一步用自动保存状态,当用户决定切换回恢复杀死进程应用。如果我理解正确的话,这种明确的杀人申请后,如果启动后,将从一开始,而不是从已保存的状态下运行。请纠正我,如果我错了。

据Android的文档,我需要的是由 ActivityManager.kil​​lBackgroundProcesses(的packageName)执行的,但是这是在做事情的编程方法。是否有一个工具,它已经提供了从用户界面同样的选择吗?

解决方案
  

如果我理解正确的,经过这样明确的查杀程序,如果启动后,将从一开始,而不是从已保存的状态下运行。

这取决于应用程序的启动。如果从启动器图标的意思是,是的。但是,用户可以通过BACK按钮返回到你,或者通过最近的任务列表中,根据情况,这些用户将返回到他们离开现场,而不是一开始。

  

有一个工具,它已经提供了从用户界面同样的选择吗?

在Android 4.0+设备,在后台的应用程序,打开最近任务列表(长preSS HOME或$ P PSS专用的最近通话启示$),并扫描应用程序关闭的权利。这似乎基本上叫 killBackgroundProcesses()在该包的名称。

我还没有试过这种在一个模拟器,但可能它做同样的事情。

For testing purposes I need to easily reproduce a situation when Android system decides to save a state of and kill a background application, in the same manner as it normally does for memory optimization purposes. In fact, I need also to test the restoration process of such a removed process when a user switches back to it.

The straighforward approach would be to open the application and then open more other tasks trying to allocate as much resources as possible. That's too complicated and unreliable.

I've found this question on SO, but the answer implies simply killing the process, which seems not an equivalent, because there seems no means for further automatic restoring of the killed process with a saved state, when a user decides to switch back to the application. If I understand correctly, after such explicit killing the application, if started, will run from very beginning, not from a saved state. Please, correct me, if I'm wrong.

According to Android documentation, what I need is performed by ActivityManager.killBackgroundProcesses(packageName), but this is the programmatic way of doing the thing. Is there an utility which already provides the same option from UI?

解决方案

If I understand correctly, after such explicit killing the application, if started, will run from very beginning, not from a saved state.

That depends on how the app is launched. If you mean from the launcher icon, yes. However, the user could return to you via the BACK button, or via the recent tasks list, depending upon circumstances, and those would return the user to the spot they left, not the "very beginning".

Is there an utility which already provides the same option from UI?

On an Android 4.0+ device, with your app in the background, open up the recent tasks list (long-press HOME or press the dedicated RECENTS affordance), and swipe your app off to the right. This appears to basically call killBackgroundProcesses() on that package name.

I have not tried this in an emulator, but probably it does the same thing.

这篇关于如何仿效Android操作系统后台应用程序的卸载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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