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 <[email protected]> написал: > 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 [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 -- 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

