I have a common async task class that starts a tcp connection using my tcp client class. I am executing this async task while my main activity is launched and I define activity as caller. Here is my async class code:
public class CommonAsyncTask extends AsyncTask<Handler,String,String> {
OnAsyncRequestComplete caller;
Context context;
String m;
List<NameValuePair> parameters = null;
ProgressDialog pDialog = null;
public TCPClient client;
public CommonAsyncTask(Activity a) {
caller = (OnAsyncRequestComplete) a;
context = a;
}
public interface OnAsyncRequestComplete {
public void asyncResponse(String m);
}
@Override
protected String doInBackground(Handler... params) {
client = new TCPClient(new TCPClient.OnMessageReceived() {
@Override
public void messageReceived(String message) {
caller.asyncResponse(message);
}
});
client.run();
return null;
}
}
When a message received I call caller.asyncResponse(message)
and it runs in given activity. From main activity I start a new activity and I want to trigger caller.asyncResponse
in this new activity and main activity simultaneously using the same async task class. If there are more then two activities I want to trigger that caller.asyncResponse
in all activities. Is it possible to do this?