Hi Noodles, I guess the problem is the following: your thread has a reference to the Activity or ListView. When the download is finished the thread uses this reference to add the items to the ListView. However when the screen orientation has changed, the activity has been destroyed and recreated and the reference points not anymore to the activity (and listview) which is displayed. Therefore your adding items (e.g. by calling setAdapter) on a listview which is not displayed.
Possible solution: - Thread has reference to activity (thread.activity) - when onRetainNonConfigurationInstance is called set thread.activity = null and return a reference to the thread - onCreate: if getLastNonConfigurationInstance returns state (not null) call state.thread.setActivity(this) - whenever your thread wants to access the activity (or the list view) it needs to make sure that thread.activity != null, if thread.activity == null the action needs to be cached for later execution (for example by using a list of runnables) I hope that helps, if something is unclear or you have additional questions don't hesitate to ask! Chrigi On Mon, Feb 8, 2010 at 5:39 PM, Noodles <brand...@gmail.com> wrote: > I have a problem with rotation, during my ListActivity is loading data > from the network. > To do it I use a background thread which recovers data and put them > inside an ArrayList. While this thread works, there is Progress dialog > activated in foreground. > > For the rotation I use the method with > onRetainNonConfigurationInstance() to save my ArrayList's state. After > android calls this method, I call dismiss() on the progress dialog on > onStop(). Then the activity is created as new with onCreate(), but it > use the getLastNonConfigurationInstance() to recover the ArrayList's > state. > > Now, my problem... > > If I rotate from portrait to lanscape when the download is terminated > and I see the data in portrait yet, everything is ok. > If I rotate during progress dialog is showing I have two cases: > > 1- onRetainNonConfigurationInstance() saves the arraylist fully > recovered, the thread terminates and everything is ok. > 2- onRetainNonConfigurationInstance() saves the arraylist empty, i > think the download isn't finished yet. > The onCreate is called and my list is empty, the thread terminates, > but i don't see anything in my list. > > ... if I am in this case and I still rotate from landscape to portrait > now I can see my list full with all the data. > > Why?? Where am I wrong? > > p.s. sorry for my english, I hope everything is clear. > > -- > 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