Reputation: 745
In my phone when minimize aplicatoin then the Android destroy activity. In Developer options I turn "Don't keep activities".
I try to implement MVP.
I have a activity with button.
Steps:
presenter.dowanloadFile()
. This is a async http request. The size of file is about 10 MB.view.hideProgress
OK. This case work fine. Nice.
But suppose the next case:
presenter.dowanloadFile()
. This is a async http request.view.hideProgress
The question is:
Is I need to continue http request when user minimize application (item 4). Or I must cancel current http request. And when user again return to application I must again start new async http request?
I want the next: When user return to application and if http request success finish then to show result. If the request is not finish then continue to wait http response.
Upvotes: 0
Views: 257
Reputation: 3263
It depends on what you want to happen? It seems like it's wasteful to cancel a request that is expensive (10 seconds is a lot), however you also need to consider what "cancel" mean in the context of an HTTP request.
For example, if cancelling a request, only prevents results from being delivered. Than means that your file was actually uploaded but you don't get callbacks anymore for that request result. Also be careful if your upload thread has a reference to your view, it will be leaked till the upload is done.
If you don't really care about the request, you can just cancel it. Assuming your server is smart enough to identify another request for the same file, so you don't duplicate it if your activity
was re-created.
Another option would be not cancelling the request. Then you would need some mechanism of having your "presenter" survive the Activity
re-creation.
There are numerous ways of doing that:
presenters
and not re-creating it if it exists in the cache.fragments
, which are basically are fragments with setRetainInstance(true) to survive an activity re-creation.Service
or JobScheduler
, and having your presenter/view only subscribe to the state of the upload process, but not actually own it.You can investigate each option individually when you decide what is the most convenient for your application.
Upvotes: 0