Re: [android-developers] About accessing List View items from a different Thread

2012-09-27 Thread Subin Sebastian
Thanks Justin, and Blake.
I was not aware of Loaders. I will try both the approaches, and will give
feedback soon.
-- 
Thanks & Regards
--
Subin Sebastian

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

Re: [android-developers] About accessing List View items from a different Thread

2012-09-27 Thread G. Blake Meike
Actually, simply notifying that the contents have changed is pretty badly 
broken.

Since the UI is single threaded, it is not thread safe and, therefore, will 
not seize any kind of lock before it tries to display the new contents of 
the list.  While that may work on some processors, it is definitely not 
correct.

The message that you are getting describes exactly what you have to do.  It 
is fine to load up the new contents of your list, in background.  You must 
not, however, put them into the list that is visible through your Adapter, 
in background.  You can either create a new list, publish it safely from 
the background thread into the UI thread, and install it in the adapter 
from the UI thread, or you can publish the raw data, safely, into the UI 
thread and then copy it into the Adapter's list, on the UI thread.

If you use AsyncTask, instead of your own thread, you can do the load in 
the doInBackground method and the copy in onPostExecute.  Better yet, have 
a look at using a Loader.

However you decide to do it, you must change the Adapter visible list only 
from the UI thread.

G. Blake Meike
Marakana

The second edition of Programming Android is now available!
http://shop.oreilly.com/product/0636920023005.do

On Thursday, September 27, 2012 11:09:08 AM UTC-7, MagouyaWare wrote:
>
> Whenever the data for your adapter changes you need to call 
> notifyDataSetChanged() on the adapter... This triggers the listview to 
> update itself.
>
> Thanks,
> Justin Anderson
> MagouyaWare Developer
> http://sites.google.com/site/magouyaware
>
>
> On Thu, Sep 27, 2012 at 11:58 AM, Subin Sebastian 
> 
> > wrote:
>
>> Hey Android Folks,
>>
>> I'm an independent developer working on a small social app project. I 
>> have my custom *Application* class extended from Application. And I have 
>> a list view adapter extended from the *BaseAdapter*. My list of data 
>> resides inside the custom application class. This is there located, to ease 
>> the sharing of data between activities. Using parcels or putting extras 
>> across activities was not very easy to use in my use case. So I decided to 
>> put the list of data inside the app class. On one activity, I have a 
>> listView which lists all this data. I created an adapter for this. In the 
>> activity class, I also have a refresh button, which does nothing but fetch 
>> more records from my server and then adds those records to the data list in 
>> the application class. This happens in a background thread. But when I do 
>> this I get the following exception log : https://gist.github.com/3795342
>>  And the source code for the adapter class is here : 
>> https://gist.github.com/3795389
>>
>> I have simplified the code for better understanding. 
>> Can someone help me out to fix this issue?
>> -- 
>> Thanks in Advance
>> --
>> Subin Sebastian
>>
>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to 
>> android-d...@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

Re: [android-developers] About accessing List View items from a different Thread

2012-09-27 Thread Justin Anderson
Whenever the data for your adapter changes you need to call
notifyDataSetChanged() on the adapter... This triggers the listview to
update itself.

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Thu, Sep 27, 2012 at 11:58 AM, Subin Sebastian
wrote:

> Hey Android Folks,
>
> I'm an independent developer working on a small social app project. I have
> my custom *Application* class extended from Application. And I have a
> list view adapter extended from the *BaseAdapter*. My list of data
> resides inside the custom application class. This is there located, to ease
> the sharing of data between activities. Using parcels or putting extras
> across activities was not very easy to use in my use case. So I decided to
> put the list of data inside the app class. On one activity, I have a
> listView which lists all this data. I created an adapter for this. In the
> activity class, I also have a refresh button, which does nothing but fetch
> more records from my server and then adds those records to the data list in
> the application class. This happens in a background thread. But when I do
> this I get the following exception log : https://gist.github.com/3795342
>  And the source code for the adapter class is here :
> https://gist.github.com/3795389
>
> I have simplified the code for better understanding.
> Can someone help me out to fix this issue?
> --
> Thanks in Advance
> --
> Subin Sebastian
>
>  --
> 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