如果活动被杀害,并在AsyncTask的生活? [英] If an activity is killed, does the AsyncTask live on?

查看:101
本文介绍了如果活动被杀害,并在AsyncTask的生活?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我知道这个问题的答案,但一个AsyncTask的继续生活在曾经的呼叫活动已完成() ED?

I think I know the answer to this, but does an AsyncTask continue to live on once its calling Activity has been finish()ed?

    protected void onPreExecute() {
        Toast.makeText(getApplicationContext(), "Your data is processing.", Toast.LENGTH_LONG);
        finish();
    }

编辑:到目前为止,两个不同的答案:)

so far two different answers :)

推荐答案

该AsyncTask的是依赖于UI线程,如果活动结束异步任务被取消。

The AsyncTask is tied to a UI thread and if the Activity is finished the async task is canceled.

[更新] 的 - 下面Hackbod的评论是正确的。应该指出的是,AsyncTasks的用意是要短暂的,因此没有太在乎这个问题。只有真正走向一个AsycTask当它完成或进程被杀死这可能会或可能不会发生完成后调用。

[update] - Hackbod's comment below is correct. It should be noted that AsyncTasks are meant to be short lived and as such not worry so much about this issue. An AsycTask is only truly gone when it is completed OR the process is killed which may or may not happen after finish is called.

这篇关于如果活动被杀害,并在AsyncTask的生活?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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