2013-08-05 29 views
0

我想在我的服務器代碼中創建自定義事件。像onMessageReceive(),onServerStarted()等,我的服務器代碼是:Android中的CustomEvents

Thread thread = new Thread(new Runnable() { 
      public void run() { 
       try { 
        String text; 
        DatagramPacket p1 = new DatagramPacket(message, message.length); 
        DatagramSocket s1; 
        try { 
         s1 = new DatagramSocket(server_port); 

         Log.d("UDP Server","Listening"); 
         s1.receive(p1); 
         text = new String(message, 0, p1.getLength()); 
         Log.d("Client Message",text); 

         stop(s1); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 

       } catch (Exception e) { 
       } 
      } 
     }); 
     thread.start(); 

我該怎麼做?通過使用CallBacks?在這個需要幫助

回答