Until this is fixed (even without setRetainInstance()), my temporary 
workaround is:

Put the following into a subclass of the AsyncTaskLoader:

public static final SparseArray<Object> loaderResults = new 
> SparseArray<Object>(); 

 

 ... 

 

public void deliverResult(Object data) {
>     loaderResults.put(getId(), data);
> } 

  

 ...


And then in your Fragment, put in something like this for onStart():

    @Override
>     public void onStart() {
>         super.onStart();
>         // Get any results that were not sent due to a bug with loaders
>         // and send them manually
>         SparseArray<Object> rArray = AbstractTaskLoader.loaderResults;
>         for (int i = 0; i < rArray.size(); ++i) {
>             int loaderId = rArray.keyAt(i);
>             // any code that you put in onLoadFinished() here, i.e. 
> dismissing dialog
>             rArray.removeAt(i);
>         }
>     }


And also in onLoadFinished() don't forget to delete() that loader's key 
from this sparse array to prevent unneeded memory from being GCed.

Hope this helps someone.

On Friday, January 13, 2012 2:54:16 AM UTC-5, Dianne Hackborn wrote:
>
> Hi, we'll look at this issue, but I would generally recommend -- don't use 
> setRetainInstance() with loaders.  It is kind-of weird to do that.  One of 
> the big points of loaders is to take care of propagating state across 
> activity/fragment instances, so there is no need to retain the instance.
>
> On Mon, Dec 12, 2011 at 11:29 PM, kaciula <[email protected]>wrote:
>
>> As I said, the initial bugs were fixed by revision 4 of ACL. However, 
>> there is still a bug present in both the ACL and Android. I've tested it 
>> with Android version 3.2 and 4.0. Check out the updated project at 
>> https://github.com/**kaciula/BugRetain<https://github.com/kaciula/BugRetain>
>>
>> I think this is a pretty important bug. The scenario is this: From 
>> activity A, go to activity B, switch once the orientation and go back to 
>> activity A. As a consequence of this bug, I can't write an app with 
>> fragments that use setRetainInstance and is available in both orientations. 
>> I really need a workaround until the Android guys fix the issue. Thoughts?
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>
>
> -- 
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to 
> provide private support, and so won't reply to such e-mails.  All such 
> questions should be posted on public forums, where I and others can see and 
> answer them.
>
>

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

Reply via email to