first of all, you are certainly on the "right direction" if you are taking in mind all the points you mentioned.
the problem you describing is very common, and concerns to most of applications
there is problem with some of your assumptions:
Activity + AsyncTask. Doesn't work at all as AsyncTask is bound to specific Activity instance and once Activity is recreated (device orientation change is an example), AsyncTask is bound to "wrong" context.
no one said AsyncTask
must been executed from an Activity
!!
it's also a good practice using AsyncTask
from android Service
derived class (not IntentService
..) . that's possible because Service
methods are executed from the main thread.
actually, that is the preferred solution to my believe.
Activity + IntentService. Activity triggers the service and provides the "request context" in Intent. Once IntentService is done, it uses sendBroadcast() to tell the Activity where we are. This doesn't work because by the moment IntentService is done, Activity can already be paused, so it won't receive the update.
if the activity already paused/destroyed - you don't have any reason to update it anyway!!!!!
instead, you can just strore this information persistently / static singeltone class, and when this activity resume - it will retreive it back, and display the relevant state.