Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
noopesh
Posts: 60
Registered: ‎05-04-2011
My Device: Torch 9800, Bold 9700, Curve 9380

Unable to understand the working of RecordStore

Hi all,

 

I have created two test application for testing record store.

 

I am using this reference for implementing the same.

 

First app inserts record in the record store and read from  there, and in the second app, I just access that record store.

 

So now, From the second app, I am unable to access first app record store.

 

If anyone have some idea regarding the same, then please share.

 

Thanks in advance.

New Developer
shivam284
Posts: 108
Registered: ‎01-23-2012
My Device: torch,bold,curve,strom

Re: Unable to understand the working of RecordStore

Hi ,

 I am thinking that your first app will not be closed proprly!

 

you can use the database if there is no other app using the same database!

Thanks & Regards,
Kumar Shivam
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Unable to understand the working of RecordStore

I suspect the problem here is that you used the default authorization for the RecordStore, in which case it is private, so only accessible from the creating application.

 

Have a look at the API, specifically the documentation for this method that you can use when creating the RecordStore.

 

public static RecordStore openRecordStore(String recordStoreName,
                                          boolean createIfNecessary,
                                          int authmode,
                                          boolean writable)

 

I think you want authmode set to AUTHMODE_ANY.

 

 

Developer
Anand04
Posts: 95
Registered: ‎06-05-2012
My Device: Developer

Re: Unable to understand the working of RecordStore

hi,

 

you can use below code:

 

On the producer side, the code can be as follows:

 

//open a record store for updates.
 RecordStore myRecordStore = RecordStore.openRecordStore("ShareableRecordStore", true);
 
 //set the mode of the record store.
 //RecordStore.AUTHMODE_ANY enables the record store to be available outside
 //the suite for other MIDlet. The second parameter denotes that
 //the record store is shared in read-only mode so that other
 //MIDlets would not be corrupting it.
 myRecordStore.setMode(RecordStore.AUTHMODE_ANY, false);
 
 //after this the producer MIDlet can do any updates on the record store
 //such as add record, update record, or delete a record using the record
 //store API.
 myRecordStore.addRecord(dataBytes,0,dataBytes.length);
 myRecordStore.setRecord(recordId, myUpdatedData.getBytes(), 0,  myUpdatedData.getBytes().length);

 

 

On the consumer side, the code can be as follows:

 

//On the consumer side there needs to be an implementation
 //of the RecordListener interface which demands to have 3
 //functions to be coded:
 //1.public void recordAdded(RecordStore aRecordStore, int aRecId)
 //2.public void recordChanged(RecordStore aRecordStore, int aRecId)
 //3.public void recordDeleted(RecordStore aRecordStore, int aRecId)
 //where aRecordStore is handle to the store and aRecId is the Id of the
 //affected record.
 
 //open the record store by providing the details
 RecordStore myRecordStore = RecordStore.openRecordStore("ShareableRecordStore","ProducerMidletSuiteVendor","ProducerMidletSuite");
 
 //register for the updates
 myRecordStore.addRecordListener(this);
 
 //here "this" denotes the object that implements RecordListener
 //whenever the producer updates the record store the appropriate
 //function (recordAdded/recordChanged/recordDeleted) shall be called
 //when there is no need for updates, unregistration can be done
 myRecordStore.removeRecordListener(this);

 

thanks,

Developer
noopesh
Posts: 60
Registered: ‎05-04-2011
My Device: Torch 9800, Bold 9700, Curve 9380

Re: Unable to understand the working of RecordStore

Hi Anand04, Thanks for quick reply.

 

Actually I am creating two different Blackberry application using Blackberry Java Plug-in for Eclipse.

 

I tried your approach too. But in the second app(Consumer side),  the following line gives the exception 'RecordStoreNotFoundException'.

 

//open the record store by providing the details
 RecordStore myRecordStore = RecordStore.openRecordStore("ShareableRecordStore"​,"ProducerMidletSuiteVendor","ProducerMidletSuite"​);

 

If you have any idea regarding the same, then please help.

Thanks in advance.

Developer
Anand04
Posts: 95
Registered: ‎06-05-2012
My Device: Developer

Re: Unable to understand the working of RecordStore

[ Edited ]

Hi noopesh,

if you have problem with RecordStore, can you use Persistent Store in your application?
Persistent store data is sharable between multiple app without any permission and easy to use in BB.

thanks,

Developer
noopesh
Posts: 60
Registered: ‎05-04-2011
My Device: Torch 9800, Bold 9700, Curve 9380

Re: Unable to understand the working of RecordStore

Hi Anand04,

Have you successfully implemented the above functionality?
If yes, then what was the application type(Blackberry Application/MIDlet) ?