在循环执行过程中,Android可以杀死我的应用程序吗? [英] Can Android kill my app while it is in the middle of a loop execution?

查看:75
本文介绍了在循环执行过程中,Android可以杀死我的应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android决定从堆栈中删除应用程序以释放某些RAM时,如果被破坏的应用程序当前正在后台运行某些循环,会发生什么情况?循环会在执行过程中终止还是VM等待其结束?

When Android decides to remove an application from the stack in order to free up some RAM, what happens if the application that is being destroyed is currently running some loop in the background? Will the loop be terminated amid execution or will the VM wait for it to finish?

推荐答案

执行过程中会终止循环吗,还是VM会等待循环结束?

Will the loop be terminated amid execution or will the VM wait for it to finish?

该循环终止,否则它不是很致命".

The loop is terminated, otherwise it isn't quite "killing".

简单测试:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                while (true) {
                    Log.i("LOOP", "Running");
                    Thread.sleep(1000);
                }
            } catch (InterruptedException e) {}
        }
    }).start();
}
}

从最近的应用程序中刷出该应用程序.

Swipe the app out from the recent apps.

这篇关于在循环执行过程中,Android可以杀死我的应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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