I've isolated the problem and this has nothing to do with ArrayList or 
Vector and everything to do with Garbage Collector.  Both of those are 
working fine exactly as I coded them when I run the code in an isolated 
activity.  Apparently GC is destorying my activity and recreating it and 
my onSaveInstanceState()/onRestoreInstanceState() code isn't working 
correctly.
 

On Thursday, July 5, 2012 1:35:07 PM UTC-7, alex b wrote:

> I saw the notice about the syncronization of the Vector type, but it 
> didn't help me find a solution to the problem.  What I believe i need to do 
> is...
>  
> lock the ArrayList, Vector whatever
> update the ArrayList
> unlock the ArrayList
>  
> but I don't know how to accomplish this.
>
>  
>
> On Tuesday, July 3, 2012 1:36:58 PM UTC-7, RichardC wrote:
>
>> I don't think Vector is thread safe in the way you expect did you read: 
>>
>> *"This class is equivalent to 
>> ArrayList<http://developer.android.com/reference/java/util/ArrayList.html> 
>> with 
>> synchronized operations. This has a performance cost, and the 
>> synchronization is not necessarily meaningful to your application: 
>> synchronizing each call to get, for example, is not equivalent to 
>> synchronizing on the list and iterating over it (which is probably what you 
>> intended). If you do need very highly concurrent access, you should also 
>> consider 
>> CopyOnWriteArrayList<http://developer.android.com/reference/java/util/concurrent/CopyOnWriteArrayList.html>
>> . "
>> *
>> http://developer.android.com/reference/java/util/Vector.html 
>>
>> The implication of the above is that your Vector change be changed from 
>> another thread whilst you are trying to serialize it.
>>
>>
>> On Monday, July 2, 2012 8:52:46 PM UTC+1, alex b wrote: 
>>>
>>> I have an activity that contains a private Vector<myobject>, thread safe 
>>> version of ArrayList.  The activity adds items to the ArrayList, and in 
>>> onSaveInstanceState() I save the data (see code below).  The problem is 
>>> that it looses items and it seems to have after the GC runs.  So what am I 
>>> missing?
>>>
>>>
>>>     private static RecentItems _lstRecent;
>>>     
>>>     @Override
>>>     public void onCreate(Bundle savedInstanceState) {
>>>         
>>>         super.onCreate(savedInstanceState);
>>>         setContentView(R.layout.main);
>>>         
>>>      restoreRecents(savedInstanceState);
>>>     }
>>>
>>>     @Override
>>>     protected void onSaveInstanceState(Bundle outState){
>>>         super.onSaveInstanceState(outState);
>>>         
>>>         String s=serializeIt(_lstRecent);
>>>         bundle.putString("lstRecent", s);
>>>     }
>>>     
>>>     @Override
>>>     protected void onRestoreInstanceState(Bundle outState){
>>>         super.onSaveInstanceState(outState);
>>>         
>>>         this.restoreRecents(outState);
>>>     }
>>>
>>>     private void restoreRecents(Bundle bundle){
>>>      if (bundle!=null){
>>>          String s = bundle.getString("lstRecent");
>>>             _lstRecent=deserializeIt(s);
>>>         }
>>>          
>>>         if (_lstRecent ==null)
>>>             _lstRecent=new RecentItems();//unt
>>>
>>>     }
>>>
>>>

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