Oh and it really doesn't make sense to set the arguments from the inflate
attributes.  I mean, the arguments are the ones coming from the content view
hierarchy.  You don't need to save them away, that just duplicates them
elsewhere, and potentially leads to ambiguous situation such as if you have
different arguments for different layouts, in which case should the last
restored arguments be used or the ones from the new layout?

On Sat, Feb 19, 2011 at 12:14 PM, Dianne Hackborn <hack...@android.com>wrote:

> Well basically onInflate() is called when it needs to be, which is when the
> content view of the activity is being inflated.  If that isn't working for
> you...  you will need to do something else.  There is no other point at
> which this can be called, the on and only point it can happen is during
> inflation of the activity's view hierarchy.
>
>
> On Sat, Feb 19, 2011 at 11:53 AM, davemac <davemac...@gmail.com> wrote:
>
>> I created a bug report for this a couple of days ago, but it doesn't
>> seem to have received any attention:
>>
>> http://code.google.com/p/android/issues/detail?id=14796
>>
>> To reproduce the problem, add the following callback override to the
>> TitlesFragment class in FragmentLayout.java under the ApiDemos project
>> in samples for Honeycomb Preview:
>>
>>        @Override
>>        public void onInflate(AttributeSet attrs, Bundle
>> savedInstanceState) {
>>                Bundle args = new Bundle();
>>                for(int i=0; i<attrs.getAttributeCount(); i++) {
>>                Log.v("14796", "    " + attrs.getAttributeName(i) +
>>                                " = " + attrs.getAttributeValue(i));
>>                args.putString(attrs.getAttributeName(i),
>>                               attrs.getAttributeValue(i));
>>                }
>>                this.setArguments(args);
>>                super.onInflate(attrs, savedInstanceState);
>>        }
>>
>> This is doing what the the documentation says you should do. That is,
>> take attributes passed in and save them in the arguments bundle on the
>> fragment instance. However, if you launch this activity then rotate
>> the screen, the activity crashes with an IllegalStateException. And it
>> does that because onInflate() gets called way too late when Android is
>> rebuilding the activity and its fragments. If the layout for the other
>> orientation is different that the previous layout, you'll have no way
>> to use any of the attributes in onCreateView() for the fragment,
>> because onInflate() isn't being called until later.
>>
>> I haven't come up with a workaround either. The fragment can't even
>> see the activity until onAttach(), and you can't set the arguments
>> bundle once onAttach() has been called.
>>
>> The sample activities so far haven't tried to utilize this feature, so
>> perhaps it won't affect most people. But for those who need or want
>> it, it doesn't seem to work.
>>
>> --
>> 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
>>
>
>
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> 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.
>
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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 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