Change:
private class AsyncSaveBitmap extends AsyncTask<Void, Void, Void> implements MediaScannerConnection.OnScanCompletedListener
to:
static private class AsyncSaveBitmap extends AsyncTask<Void, Void, Void> implements MediaScannerConnection.OnScanCompletedListener
(i.e., add the static
keyword)
This will require some follow-on changes to your onScanCompleted()
implementation, which presently relies on the fact that AsyncSaveBitmap
is not static
, calling your activity's responseListener()
method.
As it stands, so long as your task is still running, your activity is leaked, because:
You pass your AsyncSaveBitmap
to MediaScannerConnection.scanFile()
as the callback object
The callback object will be held onto by MediaScannerConnection
code until the scan is complete
The AsyncSaveBitmap
class is not static
, and so it holds an implicit reference back to the outer Java class, which in this case is your activity