11-19-2012 03:38 PM - edited 11-19-2012 04:54 PM
i am using a database in my alternate entry point, and when the user callthe GUI app some times i am getting a null pointer exeption just when i install the app , i suspect is due both app try use DB at the same time what is the best aproach to avoid this. thx
11-21-2012 11:06 AM
I have not yet had to deal with a database shared between 2 apps (if that is what you are trying to do).
At the moment blackberry implementation of sqlLite only supports 1 write connection. However can support multiple read connections (if all one app needs to do is read then open use open with the read only parameter):
Otherwise you will probably have to use a shared resource as a lock or race condition, I would suggest an object in the persistant store. And make sure that only one of the apps has an open connection at a time with it.
Hope you find something usefull in here :/
11-22-2012 10:25 AM
Your problem I would almost guarantee is nothing to do with concurrent access to the database. I am betting you have a static reference and you expect that because one app (say the one started at device startup) has set this static variable, the other app should see it.
For static variables this is unfortunately not true when the there are two different applications involved.
So basically if you want two applications sharing the same Persistent Store Object (which is perfectly supported and will work correctly), then both application have to go to persistent store and get the Object. They should save a reference to that Object. But everything should be accessed through this Object. Do not expect static variables from one application to be useful by the other one.
Hope this makes sense.
11-22-2012 11:48 AM
well i put in the run time store all my shared static variables =), anyway i will check but i have to tell u when u put sleep the background app ( started at device startup ) in the first case just when app isstalled and ppl chose run it the null pointer is gone. ( sleep = 60 sec )
11-22-2012 12:48 PM
Sorry, I'm not meaning to be hard here. Please take my comments positively.
Also don't worry about your English. It is better than my <insert language of your choice>.
The BlackBerry is an Event driven system. You don't sit in the background and process something and then, when you have finished, stop. Instead your app will listen for events, like key presses, then process these and then wait for the next event.
In an event driven system, you should normally listen for an event, rather than wait and hope the event happens.
In your case, you seem to be saying that if you wait 60 seconds, then something happens and suddenly your variable is not null. But the problem there is what is it that happens? And will waiting 60 seconds always make sure that it happens, so your variable is set?
Here are a couple of KB articles that might help.
I suspect you have seen this.
Perhaps this is your problem with your background code?