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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 15
Registered: ‎10-23-2008
My Device: Not Specified

Receiving incoming connections when midlet is running


I have a midlet that listens for incoming sms connections on sms://:50001. I use static push registration to auto start the midlet when a sms is received. That works fine. When the  midlet is running, I have a separate thread listening for sms on sms://:50001. This however does not work.


What happens is, I get a notification asking whether to start the midlet, even though it is already running. And my thread cant receive the sms. The midlet works fine when push registration is removed.


I've tested on two blackberry 8310, one with OS version 4.2 other with version 4.5. The midlet works fine in OS 4.2.


my code



public final class PushRegistryApp extends MIDlet { //The data we expect to receive. private static final String TEST_DATA = "This is just a test"; private Display theDisplay; private Form theForm; private StringItem messages; private MessageConnection mc; public PushRegistryApp() { } //Signals the MIDlet that it has entered the Active state. public void startApp() { //Get the display object for this MIDlet. theDisplay = Display.getDisplay(this); //Instantiate the form. theForm = new Form("PushRegistryApp"); //Istantiate the StringItem. messages = new StringItem("", "starting..."); //Add the StringItem to the form. theForm.append(messages); //Open the SMS connection on port 5678. try { mc = (MessageConnection) Connector.open("sms://:50001"); } catch (IOException ioe) { message("Failed to open connection: " + ioe.toString()); System.out.println("Failed to open connection: " + ioe.toString()); } //Create and start a new WorkerThread. Thread t = new WorkerThread(); t.start(); theDisplay.setCurrent(theForm); } private class WorkerThread extends Thread { public void run() { try { BinaryMessage txtMsg = (BinaryMessage) mc.receive(); message("Received: "); } catch (IOException e) { message(e.toString()); } } } //Display a String message to the user. private void message(String msg) { //Display the message in the StringItem. messages.setText(messages.getText() + "\n" + msg); } //Signals the MIDlet to stop and enter the Pause state. public void pauseApp() { } //Signals the MIDlet to terminate and enter the Destroyed state. //Unconditional when set to true. The MIDlet must cleanup and release //all resources. //Otherwise, the MIDlet may throw a MIDletStateChangeException to //indicate it does not want to be destroyed at this time. public void destroyApp(boolean unconditional) { try { //Close the connection. mc.close(); } catch (IOException ioe) { System.out.println(ioe); } }




BlackBerry Development Advisor
Posts: 15,886
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Receiving incoming connections when midlet is running

Can you elaborate on what is not working?  Is an exception thrown?  If so what is it?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.