Supposet my websocket server sends data to my android client which is defined as given below
public class ClientConnection extends AsyncTask<Void, Void, Void> {
private void connectWebSocket() {
URI uri;
mWebSocketClient = new WebSocketClient(uri) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
}
@Override
public void onMessage(String s) {
DO_MY_UI_CHANGES(s);
}
@Override
public void onClose(int i, String s, boolean b) {
Log.d("Websocket", "Closed " + s);
}
@Override
public void onError(Exception e) {
Log.d("Websocket", "Error " + e.getMessage());
}
};
mWebSocketClient.connect();
}
Now let say I want to Update my main threads UI element after receiving data from server. As of now I know that DO_MY_UI_CHANGES(s) wont work because we are trying to modify main threads element in this thread which isnt allowed in android.
Please suggest me something so that I can make call to DO_MY_UI_CHANGES.
onPostExecutemethod.onPostExecute... what happens after that is in your hands.