I am trying to establish a PIM listener that will update a MainScreen where all the contacts of the phone are listed.
What I am doing is the following:
-
I am loading for one time only a form called ContactsForm and I am storing it into the RuntimeStore
-
I created a PIMListListener to listen for all the changes that will occur in the address book.
-
When a contact is added, I am adding it to the contactsForm successfully
-
When a contact is removed, I am facing a big problem deleting it :S!!!
I am getting this exeption: “IllegalArgumentException”; this exception’s text is : UiEngine accessed without holding the event lock. I know such errors and I know how to resolve them. So I used the following code:
UiApplication.getUiApplication().invokeLater( new Runnable() { public void run() {
synchronized(UiApplication.getEventLock()) {
uiContacts.vm.delete(uiContacts.vm.getField(j));
}
}});
This should resolve the problem. But I keep getting this error again and again. How to resolve this?
Listeners, like the PIMListListener, do not receive their callbacks in the same Application context as your UiApplication. So, in your code,
UiApplication.getUiApplication()doesn’t really work the way you’d expect it to.The best thing to do would be to store a reference to your UiApplication in a place where the callback can reach it (during initialization of the UiApplication, perhaps), and then replace
UiApplication.getUiApplication().invokeLater(...)withmyUiApp.invokeLater(...), wheremyUiAppis the reference to your UiApplication which you stored earlier.