如何模拟机器人杀死我的过程 [英] How to simulate Android killing my process

查看:142
本文介绍了如何模拟机器人杀死我的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android将杀死一个过程,如果它是在后台的操作系统决定所需的资源(内存,CPU等)。我需要能够模拟在测试过程中这种行为,这样我可以确保我的应用程序正常行为。我希望能够做到这一点在一个自动化的方式,这样我可以测试应用程序行为正确,每当出现这种情况,这意味着我将不得不对此进行测试的每一个活动,等等。

Android will kill a process if it is in the background and the OS decides it needs the resources (RAM, CPU, etc.). I need to be able to simulate this behaviour during testing so that I can ensure that my application is behaving correctly. I want to be able to do this in an automated way so that I can test if the application behaves correctly whenever this happens, which means that I'll have to test this in every activity, etc.

我知道如何杀死我的过程。这是没有问题的。问题是,当我杀死我的过程(使用DDMS,亚行外壳杀 Process.killProcess()等。)Android不重新启动它以同样的方式,它会如果Android操作系统已经把它打死了自己。

I know how to kill my process. That isn't the problem. The problem is that when I kill my process (using DDMS, adb shell kill, Process.killProcess(), etc.) Android does not restart it the same way that it would if the Android OS had killed it itself.

如果Android操作系统终止进程(由于资源需求),当用户返回到应用程序的Andr​​oid将重新创建过程,然后重新创建活动的热门活动堆栈(呼叫的onCreate())。

If the Android OS kills the process (due to resource requirements), when the user returns to the application Android will recreate the process and then recreate the top activity on the activity stack (calling onCreate()).

在另一方面,如果杀的过程中, Android的假设上的活动堆栈顶部的活性顽劣,所以它会自动重新创建过程然后将删除活动堆栈顶部的活动,并重新创建,这是在顶(调用的onCreate()`)下的活动。这不是我想要的行为。我希望同样的行为时,安卓终止进程。

On the other hand, if I kill the process, Android assumes that the activity on the top of the activity stack was badly behaved, so it automatically recreates the process and then removes the top activity from the activity stack and recreates the activity that was underneath the top activity (calling onCreate()`). This is not the behaviour I want. I want the same behaviour as when Android kills the process.

只是为了形象地解释,如果我的活动堆栈看起来是这样的:

Just to explain pictorially, if my activity stack looks like this:

    ActivityA -> ActivityB -> ActivityC -> ActivityD

如果机器人杀死进程和用户返回到应用程序,机器人再现的过程,并创建ActivityD

If Android kills the process and the user returns to the application, Android recreates the process and creates ActivityD.

如果我杀的过程中,机器人将重新创建过程,并创建ActivityC。

If I kill the process, Android recreates the process and creates ActivityC.

推荐答案

要测试这对我来说是这样做的最佳方式:

The best way to test this for me was doing this:

  • 在应用程序中打开ActivityD
  • preSS主页按钮
  • 在DDMS您的应用程序(这将杀死应用程序)preSS停止
  • 找回与主场龙preSS或打开应用程序的应用程序(取决于设备)
  • 应用程序将在重新启动ActivityD(ActivityA,ActivityB,ActivityC都死了,当你回到他们将被重新创建)
  • Open ActivityD in your application
  • Press Home button
  • Press Stop in DDMS on your application (this will kill the app process)
  • Get back to the application with Home long press or opened apps (depends on the device)
  • Application will start in recreated ActivityD (ActivityA, ActivityB, ActivityC are dead and will be recreated when you get back to them)

在某些设备上,你也可以回到应用程序(ActivityD)与应用程序 - >你的发射器图标,但在其他设备上,将启动ActivityA而不是

On some devices you can also get back to application (ActivityD) with Applications -> Your launcher icon but on other devices it will start the ActivityA instead.

这是Android的文档是如何评价的:

This is what Android docs are saying about that:

通常情况下,系统会清除任务(删除所有活动从栈上面的根系活力)在某些情况下,当用户重新选择从主屏幕上的任务。通常情况下,如果用户没有访问过的任务的一个特定量的时间,例如30分钟这完成

Normally, the system clears a task (removes all activities from the stack above the root activity) in certain situations when the user re-selects that task from the home screen. Typically, this is done if the user hasn't visited the task for a certain amount of time, such as 30 minutes.

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

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