when we use for example
new Thread(new Runnable() {
public void run() {
try {
DatagramSocket clientsocket= new DatagramSocket(5005);
byte[] receivedata = new byte[30];
while(true) {
DatagramPacket recv_packet = new DatagramPacket(receivedata, receivedata.length);
Log.d("UDP", "S: Receiving...");
clientsocket.receive(recv_packet);
String receivedstring = new String(recv_packet.getData());
Log.d("UDP", " Received String: " + receivedstring);
InetAddress ipaddress = recv_packet.getAddress();
int port = recv_packet.getPort();
Log.d("UDP", "IPAddress : " + ipaddress.toString());
Log.d("UDP", "Port : " + Integer.toString(port));
}
} catch (SocketException e) {
Log.e("UDP", "Socket Error", e);
} catch (IOException e) {
Log.e("UDP", "IO Error", e);
}
}
}).start();
Are we generating an independent thread to the activity that will continue executing the run()
until we close the APP or stop it in some way? And if so. Can we interact with the interface from this thread? I currently use an Intent Service but maybe this option is more appropriate.