I am trying to save 10 String values in PersistentStore
in my BlackBerry App. The idea is to save the newest 10 items (String values) at any given time. When the first 10 values are saved and the 11th value is typed, it should:
- Delete the first entry
- Move the remaining 9 entries above the order
- Save the 11th entry as the 10th value
This is the logic I want to follow. As the entries keep increasing, I will store maximum 10 entries which would be the latest 10 values. I tried saving the String
values through the saveChatMsg()
method:
public void saveChatMsg()
{
if(xx<10)
{
PersistentStoreHelper.persistentHashtable.put("chatMsg"+xx,chatToSave);
xx=xx+1;
if(xx==10)
{
PersistentStoreHelper.persistentHashtable.put("xxValue",Integer.toString(0));
}
else
{
PersistentStoreHelper.persistentHashtable.put("xxValue",Integer.toString(xx));
}
}
}
where xx is an int that goes through 0 upto 9. However, while this is saving the message, when I retrieve the message, it is not displayed in a chronological order. This method is called at 4 different places and so the 10 messages saved are not in the right order; newest message might appear as the 6th value instead of 10 etc. Kindly comment and advice how to implement.