I'm fetching data from WebSocket with OkHttp, and then I'm displaying it on an Android emulator with runOnUiThread (MainActivity). There are multiple server responses (events).
The onMessage function of my WebSocketListener looks like that:
@Override
public void onMessage(WebSocket webSocket, String text) {
while (text.contains("someEventName")) {
output("Receiving : " + text);
}
}
So that's how I get special events displayed as a text response.
Is there any possibility to actually get this data as some new object or maybe global variable, in order to use it anywhere else or to pass it to some other activity?
Let's say - using OkHttp, the socket and its listener, what else should I do to be able to use/save/pass the data which comes from the server as just a text?
What exactly is happening in onMessage? Do we just read?