Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are many ways you can try beside the AsyncTask. And if you try to find a best practice, AsyncTask isn't a good option. <a href="https://stackoverflow.com/a/13082084/719212">This answer</a> explains why you should not use AsyncTask. And they recommend you using a better way which can deal with long running task, <a href="https://github.com/octo-online/robospice" rel="nofollow noreferrer">RoboSpice</a>. <br>I have already used this library and I think it is worthy to try: respect activities lifecycles (orientation change), no memory leaks, supports multi-threading, caches results... It can plug and unplug long request task by using cache (but it can't work well for a non-cache request). </p> <p>But I recommend a good way comes from Google: <code>IntentService</code> and <code>BroadcastReceiver</code>. You will registered and unregistered broadcast during orientation change to receive the data result. All background task will work in IntentService and notify whatever you want to activity by BroadcastReceiver. There are a lots of example that you can try. Something like this: <a href="http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/" rel="nofollow noreferrer">http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/</a></p> <p><strong>Update</strong>:</p> <blockquote> <p>Hi R4j, the point is my application is quiet complex. And I've to make number of parallel network calls. Your approach with IntentService is good but isn't suitable for complex scenarios</p> </blockquote> <p>I don't think this is a problem. You can do anything with the IntentService, even the complicated tasks. If you want parallel tasks, you may consider a Service with multithreading in it and communicate with activity by Intent. Sending intent between Service and activity is safe and flexible, that is Android way. <br>And if you want to cache (by file download, stream, by database..) <code>RoboSpice</code> is a best choice for you</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload