Will this change break CursorLoader in multi-fragment Activities?

If I have an Activity with 2 Fragements, each fragment using a CursorLoader 
to load its own data. CursorLoader is derived from AsyncTaskLoader which 
uses AsyncTask to do the work which includes monitoring for data changes 
therefore the AsyncTask (in the Loader) cannot finish until the activity is 
closed.  How can the 2nd CursorLoader run if the 1st never finishes?

--
RichardC


On Friday, April 20, 2012 10:24:34 PM UTC+1, Dianne Hackborn wrote:
>
> Yes if your targetSdkVersion is >= 12, then as of that release the default 
> executor is serial.
>
> This change was made because we realized we had a lot of bugs in the 
> platform itself where async tasks where created that had implicit ordering 
> dependences, so with the default parallel execution there were subtle rare 
> bugs that would result.
>
> I can't address how much smarter you are than the rest of us, but I am 
> pretty convinced that for the vast majority of us the best thing to do is 
> have the default here be safe, allowing developers to change it for the 
> specific cases where they don't want that behavior.
>
> This is a lesson I seem to learn every few years: multithreading is hard. 
>  Once you think you now understand it and are an expert, you are heading 
> soon to another painful lesson that multithreading is hard.
>
> Having an API to set the default executor back to parallel is not a 
> solution, because it just gives you an easy way to create the exact same 
> problems we are trying to fix.  For example, if you have an async task that 
> executes due to some user input to update some data, there is a very very 
> good chance that if you allow these to be parallel you will have a bug.
>
> Even with something as simple as a check box (which is one of the real 
> cases that drove this change) you can have this problem.  If you run an 
> executor to save to disk the new state of the check box, there *are* 
> situations where if you tap long enough and the CPU is loaded in the right 
> way, you will end up with the first state being saved after the second.
>
> So, yes, the default is serial, and you must explicitly decide when to use 
> a parellel executor.  You should only use a parallel executor when you know 
> this is what you want and it is safe: when it is something that can take a 
> significant amount of time, and you know has no dependencies with any other 
> background tasks you may execute.  So in your example here, the solution is 
> to run your download task with AsyncTask.THREAD_POOL_EXECUTOR and leave the 
> others with the default serial executor.
>
>
>  

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to