Hi Kostya,

Thanks to try to help to sort this out. unfortunatly I don't think this is
the cause in this case:

Activity A is a TabActivity that embeds activity B being in tab 2. Indeed
when I select tab 1 from activity B using setCurrentTabByTag , *Activity A
is already in running state* (I checked onResume was called earlier), so I
dont think onRestoreInstanceState will be called here.

Also I tried to place a breakpoint in onItemSelected, but this was no help,
it seems to be triggered using runOnUIThread() or similar.

But on the idea, you are probably close. It seems Android is trying to
restore an old state (spinner position). Either this is a bug, or I did not
correctly used setSelection. I am wondering if calling setPosition from
another activity is a safe pratice??

Thierry.


2011/3/2 Kostya Vasilyev <kmans...@gmail.com>

>  Thierry,
>
> I think you are seeing interaction between the activity's
> onRestoreInstanceState and your setSelection.
>
> Should be pretty easy to check by overriding onRestoreInstanceState in
> ActivityA and/or the spinner and logging them - as well as your code that
> calls setSelection. Then you can re-run both scenarios from your original
> email and watch the exact sequence of events.
>
> -- Kostya
>
> 02.03.2011 12:52, Thierry Legras пишет:
>
>
> Okay, as I could not find a way to fix that smoothly, I just used a flag
> ignoreNextOnItemSelected like described hereafter. Seems to me a dirty hack
> :(
>
> // called from another activity context
> updateSpinnerSelection(int newposition) {
>
>     mPosition = newposition; // store it
>     mSpinner.setSelection(newposition);
>     ignoreNextOnItemSelected= true;
>  }
>
> and
>
> public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
>                 long rowid) {
>     if (ignoreNextOnItemSelected) {
>         // position might be outdate ?!?! just reapply mPosition
>         ignoreNextOnItemSelected = false;
>
>         // required
>         mSpinner.setSelection(mPosition);
>     } else {
>         mPosition = position;
>         ... // do usual stuff
>     }
> }
>
>
>
> 2011/2/25 Thierry Legras <tleg...@gmail.com>
>
>> Hi,
>>
>> I have a strange behavior in a very specific case and wonder if the issue
>> comes from my code or not.
>>
>> I have a TabActivity A with 2 tabs:
>> - Tab 1 content is created as a view with a spinner in it
>> - Tab 2 content is an activity B.
>>
>> I want at some point when Tab2 is selected to switch to Tab 1 and update
>> spinner selection in it.
>>
>> Case 1)
>> Tab 2 is selected, from Activity B context:
>>
>> activityA.updateSpinnerSelection(newposition);
>> activityA.getTabHost().setCurrentTabByTag(tab1tag);
>>
>> later AdapterView.OnItemSelectedListener.onItemSelected is called with my
>> newposition
>>
>> => so this *usually *works fine:
>>
>> Case 2)
>> Tab 2 is selected, from Activity B context, but before doing the same
>> things, if the users for some reason *first open a new acticity C on top
>> of B (like preference screen) and close this activity C*, (so A and B are
>> paused then resumed), then if I later try again the same things:
>>
>> activityA.updateSpinnerSelection(newposition);
>> activityA.getTabHost().setCurrentTabByTag(tab1tag);
>>
>> so far so goog, but later
>> AdapterView.OnItemSelectedListener.onItemSelected is called not with
>> newposition as argument *but with the older position value*.
>>
>>
>> I hope the description is clear.
>>
>> Did I missed something? or could this behavior dues to some bug in
>> Android?
>>
>> Thanks for any help,
>> --
>> Thierry.
>>
>
>
>
> --
> Thierry.
> --
> 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
>
>
>
> --
> Kostya Vasilyev -- http://kmansoft.wordpress.com
>
>  --
> 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




-- 
Thierry.

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