I am facing an issue in storing data in persistence store,i am trying to store events for different dates in persistence store but the data is getting overridden the code is :
public ListEventScreen(Vector v,String timezone) {
for(int i=0;i<v.size();i++){
EventBean bean=(EventBean)v.elementAt(i);
//a normal label in the app, just to display text, anchored left
LabelField label = new LabelField(bean.getSummary(),LabelField.FIELD_LEFT);
//add the label to the screen
add(label);
saveUserInfo(v);
}
}
public void saveUserInfo(Vector vectorData){
// static{
store = PersistentStore.getPersistentObject( 0x1dfc10ec9447eb14L );
synchronized(store) {
store.setContents(vectorData);
store.commit();
}
//}
}
Please let me know what has to be changed.
Every time you call
store.setContents(), the current contents of thepersistentStoreare overwritten with theVectoryou are passing in. You need to make sure you are loading the previous events that were already in thepersistentStoreinto yourVectorbefore then adding new events into thatVectorthat you are then saving.You are also calling
saveUserInfo()on every iteration of your loop inListEventScreen(). You should be calling it outside of the loop instead.I would do something like this:
.
If you do not mind changing the format of your persistent store contents, I would wrap the store in a singleton class instead:
.