I have an activity A which has socket communication, and I'm opening activity B on click of a button with intent from Activity A.
public void onClick(View v) {
//open preferences activity
intent = new Intent(MainActivity.this, PreferencesActivity.class);
//using some bundle here to send data
.....
MainActivity.this.startActivityForResult(intent, 1);
}
Now, if at all any socket communication happens in activity A then I have to identify that (some communication happened in activity A) in activity B and need to close activity B and bring the activity A to foreground as well. Socket communication is as follows.
ConnectSocket();
while (true) {
//wait for socket client
socClient = (SSLSocket) sslServerSocket.accept();
//once socket is connected send it back to activity
if (socClient != null) {
if (socketThread != null) {
connectedSocket = socClient;
socClient = null;
communicationThread = new ReadSocketThread();
communicationThread.start();
}
}
}
}
Here ReadsocketThread() is a thread that read the socket for messages.
How to notify activity B that something happened in activity A. I tried using handler to send message but not successful as handler in activity A never sends message to activity B. As a beginner, may be I am not using properly.