AutoCloseableList
A set of closeables.
Android API <19 does not support try-with-resources. This set is useful to cope with this problem by sticking pointers and other closeables into it to make it easier to close them, all at once.
When used in AsyncTask, the usual use case would be something like this:
@Override
protected Result doInBackground(Params... params)
{
CloseableSet cs = new CloseableSet();
try
{
ObjectWithPointer owp = cs.add(someMethodReturningPointer());
⋮
AnotherObjectWithPointer aowp = cs.add(someMethodReturningAnotherPointer());
⋮
}
finally
{
cs.close();
}
return res;
}
Content copied to clipboard