Вопрос

How do I iterate through all recordstore for a j2me app?

The recordstore are created by the user when he enters some data. So number of recordstore is not in my control.

So does the app keep track of all recordstore associated with a j2me app? OR should I create a recordStore that will contain name of all other recordstores?

I can get all the row from a recordstore using

for(int i=1;i<=getnumrecords(RecordStoreName);i++)
RecordStoreName.getrecord(i);

But I am looking for such functionality for getting all the recordstore name associated with my app.

The reason I am creating a new RecordStore instead of a new row in one recordstore is because the size of a recordstore in java me is limited by the phone.

So I have decided to create a new recordStore for every data I get from a form .

Это было полезно?

Решение

If your user can remove entries from a RecordStore your loop will probably break because of an InvalidRecordIDException on the call to getRecord.
A safer approach to iterate the records is to use a RecordEnumeration:

RecordEnumeration re = RecordStoreName.enumerateRecords(null, null, false);

while (re.hasNextElement()) {
    RecordStoreName.getrecord(re.nextRecordId());
}

Update after comments

You can use static method listRecordStores. According to API:

Returns an array of the names of record stores owned by the MIDlet suite. Note that if the MIDlet suite does not have any record stores, this function will return null. The order of RecordStore names returned is implementation dependent.

Другие советы

This functionality is provided for application developers with RecordStore.listRecordStores API:

Returns an array of the names of record stores owned by the MIDlet suite. Note that if the MIDlet suite does not have any record stores, this function will return null. The order of RecordStore names returned is implementation dependent...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top