Closed mucahitsidimi closed 4 years ago
What do you mean on
methods don't work? They are just registering handlers and will run when the client receives the corresponding message from the server.
Sorry I said method. That's exactly what I mean. I am registering handlers and sending objects. As I explained in the above;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
...
hubConnection.on("NewMessage", chatMessageModel -> {
// expected : when new message comes from server, trigger this block
}, ChatMessageModel.class);
...
}
public void sendMessage(ChatModel chatModel){
// expected : when new message sending, send message with use this block
hubConnection.send("SendMessage", chatModel);
}
new HubConnectionTask().execute(hubConnection);
or hubConnection.start();
it's not blocking main thread. Activity open normally. // This method works. I can send message to server.
public void sendMessage(ChatModel chatModel){
hubConnection.send("SendMessage", chatModel);
}
hubConnection.on("NewMessage", chatMessageModel -> {
// This block doesn't get trigger. I am sending message from server but callback not work.
}, ChatMessageModel.class);
hubConnection.start().blockingAwait();
. It's blocking main thread and activity does not open for a while. But everything works.I want to learn how we can sending - receiving objects successfully without blocking main thread.
Ok, trying to gather all the info and verify I understand it correctly. Could you take a look at this list and verify that it's correct and that I'm not missing a scenario?
hubConnection.start().blockingAwait();
from onCreate
, .on(...)
handlers work?hubConnection.start();
from onCreate
, .on(...)
handlers don't work?hubConnection.start();
or hubConnection.start().blockingAwait()
from AsyncTask
, .on(...)
handlers don't work?Also, can you enable logging so we can see whats happening in the client? https://docs.microsoft.com/en-us/aspnet/core/signalr/java-client?view=aspnetcore-3.0#add-logging
Ok, trying to gather all the info and verify I understand it correctly. Could you take a look at this list and verify that it's correct and that I'm not missing a scenario?
- Calling
hubConnection.start().blockingAwait();
fromonCreate
,.on(...)
handlers work?- Calling
hubConnection.start();
fromonCreate
,.on(...)
handlers don't work?- Calling
hubConnection.start();
orhubConnection.start().blockingAwait()
fromAsyncTask
,.on(...)
handlers don't work?
.on(...)
handlers work but activity opening late. (blocking main thread).on(...)
handlers don't work, activity opening normally..on(...)
handlers don't work, activity opening normally.Also, can you enable logging so we can see whats happening in the client? https://docs.microsoft.com/en-us/aspnet/core/signalr/java-client?view=aspnetcore-3.0#add-logging
Did you get a chance to try this out?
I am so sorry. It was my fault. I have tried to use send objects before connection done. My handlers work only when I joined to chats room with
hubConnection.send("JoinChats", chatModelList);
I update my code and JoinChats after connection done. All cases work now.
Thank you again.
When I try to use your sample code and start hubConnection in AsynTask send method works but on method does not work.
public class ChatActivity extends BaseActivity {
}
If I try to connect hubConnection in onCreate() without AsyncTask as below everything work fine but .blockingAwait() is blocking main thread and activity does not open for a while.
public class ChatActivity extends BaseActivity {
}
If I trying to connection just with hubConnection.start(); , send methods work but on methods not working again.
public class ChatActivity extends BaseActivity {
}
How can we start activity and make the on methods work without locking the main thread?