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);
}
}
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?
Unless
NewTaskis inner non static class inOlderTaskit will not prevent GC from collectingOlderTaskunless you store reference to it in some other way.But even if GC will wait until
NewTaskis done it should not be a big deal unless you save lot of data inOlderTaskor create lots of copies ofOlderTask.So if your design requires doing that, it’s ok. But it surely cleaner not to have chained tasks.