Android的AsyncTask的启动另外一个的AsyncTask [英] Android AsyncTask Starting Another AsyncTask

查看:221
本文介绍了Android的AsyncTask的启动另外一个的AsyncTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在做这样的事情在AsyncTask的的onPostExecute方法,其中 NewTask 终止的的对正在执行当前的任务:

I'm currently doing something like this in the AsyncTask's onPostExecute method, where NewTask is not the current task that's executing:

private class OlderTask extends AsyncTask<String, Void, Integer> {
    //other functions (not important)

    @Override
    protected void onPostExecute(Integer result) {
        new NewTask().execute(null, null);
    }
}

我不知道这是不是一个坏主意。将这样做会导致GC为OlderTask等待NewTask?是否有使用这种方法的任何其他可能出现的问题?

I'm wondering if this is a bad idea. Will doing so cause GC for the OlderTask to wait for the NewTask? Are there any other possible problems with using such an approach?

如果这是一个问题,我该怎么纠正呢?

And if this is a problem, how can I rectify it?

推荐答案

除非 NewTask 是内部的非静态类在 OlderTask 也不会从收集prevent GC OlderTask 除非你存储在一些其他的方式引用。

Unless NewTask is inner non static class in OlderTask it will not prevent GC from collecting OlderTask unless you store reference to it in some other way.

但是,即使GC会等到 NewTask 做它不应该是一个大问题,除非你节省大量的数据,在 OlderTask 或创造了大量 OlderTask 的副本。

But even if GC will wait until NewTask is done it should not be a big deal unless you save lot of data in OlderTask or create lots of copies of OlderTask.

所以,如果您的设计需要这样做,它的确定。但它肯定不是清洁有链接的任务。

So if your design requires doing that, it's ok. But it surely cleaner not to have chained tasks.

这篇关于Android的AsyncTask的启动另外一个的AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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