06-10-2010 11:50 PM - edited 06-10-2010 11:54 PM
Hello gurus.
I have run into a little trouble with my application and I would really appreciate it if someone could lend a helping hand.
I have an application that needs to monitor incoming PIN messages and based on the subject take certain actions. The actions also vary depending on which page of the GUI is displayed if any at all. Here is the setup:
SECURESCREEN is the main entrance and extends UiApplication.
PinListener is the background app which uses an alternate entry point.
At a certain point users will need to exchange certain information in order to create an association between each other. User “A” sends a request by pressing on a button on the UI. The message gets sent successfully with the appropriate subject . User B’s listener in PinListener (background app) captures the event :
if (messageFolder.getType() == Folder.INBOX && orginalMessage.getSubject().startsWith("ACM$"))
{
if (orginalMessage.getSubject().equals(TheSbj1)) //received request
{
try {
HandShake(0,new String(Base64InputStream.decode(orginalMessage.get
} catch (IOException e1) {
orginalMessage.getFolder().deleteMessage(e.getMess
}
}
}
Here is the code of the HandShake function (in PinListener, the background app):
private void HandShake(final int Type, final String UID, final byte[] Tranz, Message M)
{
if (MYSECURESCREEN != null )
{
//Grab the lock for the running SECURESCREEN.
MYSECURESCREEN.invokeAndWait(new Runnable()
{
public void run()
{
//Check if the peer is on the association page
if (SECURESCREEN.getUiApplication().getActiveScreen()
{
String MCode = MYSECURESCREEN.VPN(UID, Tranz,Type);
try {
Message msg = new Message();
PINAddress recipients[] = new PINAddress[1];
recipients[0] = new PINAddress("2100000A", "TEST");
msg.setSubject(TheSbj2);
msg.setContent(MCode);
Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
});
}
}
Everything is going well untill the Transport.send(msg) gets called and the application freezes. I tried sending the message from the function VPN in SECURESCREEN, abviously the same thing happens (application freezes). Does any one have any idea why this is happenning.
Thank you in advance
Solved! Go to Solution.
06-11-2010 12:59 AM
Why are you doing an invokeAndWait?
It doesn't seem like you need to interact with the screen at the point that you're running that function so why do you need a lock?
Just wondering.
06-11-2010 01:03 PM - edited 06-11-2010 04:52 PM
Hi Jerome,
Thank you for the reply. Actually I do need to use the MYSECURESCREEN.invokeAndWait(new Runnable() because of the way the association between the users is made. That is, user "A" has to be viewing the "association page" and user "B" has to also be on the "AddContactScreen" screen on his blackberry.
Basicaly, the first condition is receiving a message and checking its subject. After this, it is checking if the user is on the required page (SECURESCREEN.getUiApplication().getActiveScreen() .toString().equals("AddContactScreen")).
When these conditions are satisfied the method "VPN" in SECURESCREEN calculates the required keys, informs the user that an association request was captured and fills in the required label fields. Finally the method returns a base 64 encoded byte to be set as the content of the PIN message.
06-12-2010 11:41 AM
/bump
06-12-2010 12:44 PM
Ok guys, I changed the InvokeAndWait to InvokeLater and it works.