Closed alexei-28 closed 6 years ago
I just can speculate, but it seems like you have two instances of your presenter. The first time your Activity is instantiated your Presenter (lets call it PresenterInstance1) is instantiated too and you begin to download your file.
Next you "minimise" the activity but since you have "Don't keep activities" enabled, the whole activity is destroyed (and so is the PresenterInstance1, presenter.destroy()
should be called). But it seems that you never cancel the download file request (should be done in presenter.destroy() ).
So then you reopen your Activity and a new presenter instance (lets call it presenterInstance2) is created and starts downloading again ...
Meanwhile, the presenterInstance1 get's its callback onSuccess()
called, but this presenter is already "destroyed", so the View (activity) will never be attached to presenterInstance1. This is usually a memory leak. You better move downloading files into a background service (out of the lifecycle of the activity / presenter) and let the presenter just listen to the download service.
In my phone when minimize aplicatoin then the Android destroy activity. In Developer options I turn "Don't keep activities".
Case:
onClickDownloadPdf()
downloadToAppDir
call methodifViewAttached(OfferDetailsView::showProgress);
model.downloadFile(pdfUrl, new DefaultRestClientCallback<ResponseBody>())
onSuccess()
the presenter call method from view:onceViewAttached(OfferDetailsView::hideProgress);
And this method success call (in logcat has text: OfferDetailsPdfActivity( 2759): hideProgress:)Here logcat:
Here my activity
In activity I have 2 methods that must call when async http request finish.
Here presenter:
And all work fine. Nice.
But has problem when minimize activity.
Case:
User click on button in the activity
In activity call method:
onClickDownloadPdf()
In presenter in method
downloadToAppDir
call methodifViewAttached(OfferDetailsView::showProgress)
;Start async http request:
model.downloadFile(pdfUrl, new DefaultRestClientCallback<ResponseBody>())
User minimize application
Activity is destroy
After 2 seconds user return to application
Activity show again with progress. OK (It's correct)
After 5 seconds presenter get success http response
As result in method
onSuccess()
the presenter TRY to call method from view:onceViewAttached(OfferDetailsView::hideProgress)
; And this method is NOT call (in logcat has NO text: OfferDetailsPdfActivity( 2759): hideProgress:).As result progress bar is NOT hide.
Here logcat:
Questions:
onceViewAttached(OfferDetailsView::hideProgress)
not help here?