Why does the following code freeze all operations on the phone? The app reads the incoming sms’s, but the app doesn’t open. Right after the app is clicked, the phone freezes. What am I doing wrong. I would appreciate any help.
try {
//A DatagramConnection is created to listen for any incoming sms's.
DatagramConnection _dc =
(DatagramConnection)Connector.open("sms://");
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
byte[] bytes = d.getData();
String address = d.getAddress(); //The address of the sms is put on a string.
String msg = new String(bytes); //The body of the sms is put on a string.
} catch (Exception me) {
}
Run your code inside thread (this is worst code that I wrote):