I have to receive packets in one service and then active activity should receive it. What's the best way to do this? Some handlers, messages, broadcast receivers...?
I have this code in service:
@Override
public void onStart(Intent intent, int startId) {
Runnable myRunnable = new Runnable() {
public void run() {
while(true) {
try {
DatagramSocket socket;
socket = new DatagramSocket(4444);
socket.setBroadcast(true);
byte[] buffer = new byte[1024];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
myThread = new Thread(myRunnable);
myThread.start();
}
How could I send every packet to running activity so this activity will be controlled by packets?
Thanks for answers.