To represent multiple tasks, I'd use any suitable data structure (hash map,
sparse array, plain java array, etc.)

I'd then carry this entire data structure across configuration changes,
making sure to get it in onCreate.
 22.12.2011 3:35 пользователь "João Rossa" <joao.ro...@gmail.com> написал:

> Ok, so if you had a spinner where each option would be used as a parameter
> to an async task but you didnt want to repeat that same async task after
> rotating what would be best approach?
>
> regards,
>
> On Wed, Dec 21, 2011 at 11:24 PM, Kostya Vasilyev <kmans...@gmail.com>wrote:
>
>> You can launch the task any place you like, just don't expect to be able
>> to check if one already exists by calling getLast... (sorry, I'm not typing
>> that again) anywhere but in onCreate.
>>
>> So: call getLast in onCreate, save the value someplace, and then you'll
>> have a way of checking if you need to launch a new task or wait for an
>> existing one to complete.
>> 22.12.2011 3:18 пользователь "João Rossa" <joao.ro...@gmail.com> написал:
>>
>> But if i want to launch a task based on the spinner value how do you that
>>> without calling the task in the itemlistener?
>>>
>>> regards,
>>>
>>> On Wed, Dec 21, 2011 at 10:34 PM, Kostya Vasilyev <kmans...@gmail.com>wrote:
>>>
>>>> The spinner has nothing to do with this, per se.
>>>>
>>>> Get your exising task, if any, by calling getLast... *inside onCreate*.
>>>>
>>>> 22 декабря 2011 г. 2:19 пользователь João Rossa <joao.ro...@gmail.com>
>>>> написал:
>>>> > So basically you can not use the combination of
>>>> > onRetainNonConfigurationInstance()/
>>>>  getLastNonConfigurationInstance () with
>>>> > the task inside the spinner listener????because i wanted to aunch
>>>> tasks
>>>> > according to the option selected of the spinner....
>>>> >
>>>> >
>>>> > 2011/12/21 Kostya Vasilyev <kmans...@gmail.com>
>>>> >>
>>>> >> The value returned by getLastNonConfigurationInstance is cleared to
>>>> >> null very soon after you're supposed to have used it - onCreate.
>>>> >>
>>>> >> So, don't delay, make it quick, grab it while you can, inside your
>>>> >> onCreate, and hold on to it.
>>>> >>
>>>> >> ( IIRC, the value doesn't stay around long enough to be retrieved in
>>>> >> onStart or onResume -- not to mention much later, when the UI is
>>>> >> completely up and running with your spinner )
>>>> >>
>>>> >> -- Kostya
>>>> >>
>>>> >> 22 декабря 2011 г. 0:06 пользователь Bluemercury <
>>>> joao.ro...@gmail.com>
>>>> >> написал:
>>>> >> > Hi all! so currently i have an activity that laucnhes an async
>>>> task from
>>>> >> > inside the spinner onItemSelected method with the select int year
>>>> value:
>>>> >> >
>>>> >> > spinYears.setOnItemSelectedListener(
>>>> >> > new OnItemSelectedListener() {
>>>> >> >
>>>> >> > @Override
>>>> >> > public void onItemSelected(AdapterView<?> item, View arg1,
>>>> >> > int arg2, long arg3) {
>>>> >> >
>>>> >> > yearSelected=(Integer) item.getSelectedItem();
>>>> >> > doAsyncTask();
>>>> >> >
>>>> >> > }
>>>> >> >
>>>> >> > @Override
>>>> >> > public void onNothingSelected(AdapterView<?> arg0) {
>>>> >> > // TODO Auto-generated method stub
>>>> >> >
>>>> >> > }});
>>>> >> >
>>>> >> > here's the doAsyncTask method:
>>>> >> >
>>>> >> > /**
>>>> >> > * do asynctask for background work
>>>> >> > */
>>>> >> > public void doAsyncTask(){
>>>> >> > //get task back in case of rotation
>>>> >> > task= (QuadrosMobileActivityTask<?, ?,
>>>> >> > ?>)getLastNonConfigurationInstance();
>>>> >> >
>>>> >> > if(task==null){
>>>> >> > task=new PeriodoFeriasDbAsyncTask(this);
>>>> >> >
>>>>   ((PeriodoFeriasDbAsyncTask)task).execute(yearSelected);
>>>> >> > }else{
>>>> >> > task.attach(this);
>>>> >> > }
>>>> >> > }
>>>> >> >
>>>> >> >
>>>> >> > if i rotate the phone the task runs again, but if i put the
>>>> >> > doAsyncTask()
>>>> >> > method call outside of the listener it works as it should.....any
>>>> reason
>>>> >> > for
>>>> >> > this?why would calling a task inside the spinner listener be
>>>> different?
>>>> >> >
>>>> >> > regards,
>>>> >> >
>>>> >> >
>>>> >> > --
>>>> >> > 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
>>>> >>
>>>> >> --
>>>> >> 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
>>>> >
>>>> >
>>>> > --
>>>> > 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
>>>>
>>>> --
>>>> 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
>>>>
>>>
>>>  --
>>> 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
>>
>>  --
>> 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
>>
>
>  --
> 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

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