2012-07-10 62 views
-2

为什么下面的代码会冻结手机上的所有操作?该应用程序读取传入的短信,但该应用程序无法打开。点击应用程序后,手机就会冻结。我究竟做错了什么。我将不胜感激任何帮助。手机在收听短信时会死机

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) { 

} 
+1

尝试运行内螺纹 – 2012-07-10 10:21:11

+0

代码能否请您为我提供关于如何做一个代码示例? – BirthOfTragedy 2012-07-10 10:35:38

回答

3

内运行线程的代码(这是我写的最糟糕的代码):

new Thread() { 
    public void run() { 
     DatagramConnection _dc = 
     (DatagramConnection)Connector.open("sms://"); //A DatagramConnection is created to listen for any incoming sms's. 

     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. 
    } 
}.start();