Issue
I've been experimenting with SignalR client in an Android app connecting to a C# server hub.
When the Main Activity launches I want to invoke a call to grab the current List data from the server and call back when it's received so the RecyclerView can be loaded
However I can't seem to get the HubConnection.Invoke method to return a value, I've confirmed the hub is certainly receiving the request and is returning a value with the below;
public async Task GetActiveAlarms()
{
Console.WriteLine("GetActiveAlarms Called");
await Clients.Caller.SendAsync("GetActiveAlarms", Program.activeAlarms);
}
In the client I am calling using the below and using the doOnComplete callback
hubConnection.invoke("GetActiveAlarms").doOnComplete {
//is never called
}.blockingAwait()
However the .on listener for "GetActiveAlarms" is called, which indicates the hub is receiving the request and responding.
Unfortunately I can't find a huge amount of information on the SignalR library for Java so I may be doing it all wrong.
Thanks!
Solution
Change your hub method to return the value instead of sending a message back to the client.
e.g.
public string GetActiveAlarms()
{
Console.WriteLine("GetActiveAlarms Called");
return Program.activeAlarms;
}
Answered By - Brennan
Answer Checked By - Mary Flores (JavaFixing Volunteer)