Comments (6)
To do that, you can use the SignalRFuture done and onError handlers.
For instance, when you use the invoke method, you can do the following:
proxy.invoke("myMethod", "MyParameter")
.done(new Action<Void>() {
@Override
public void run(Void obj) throws Exception {
// Success
}
})
.onError(new ErrorCallback() {
@Override
public void onError(Throwable error) {
// Error handling
}
});
from java-client.
ErrorCallback works great, but done does not work. "Done" runs on different thread from main UI Thread. If you want to dismiss loading dialog or use any UI operation, you don't it. After i saw this problem, i try to getResult() but i have to listen getResult() while operation finished. Finally, i added my callbacks.
You can try below sample code. Your advised sample code is not working for UI operation but Logger is working. If you want to work on UI Thread, you must implement new Handler for UI Thread. To summarize, you need to change callbacks for usability.
proxy.invoke("myMethod", "MyParameter")
.done(new Action<Void>() {
@Override
public void run(Void obj) throws Exception {
Log.i("DONE TEST", "DONE TEST");
Toast.makeText(context, "DONE TEST", Toast.LENGTH_SHORT).show();
// You must implement new Handler for UI Thread.
}
}).onError(new ErrorCallback() {
@Override
public void onError(Throwable error) {
Toast.makeText(context, "ERROR TEST", Toast.LENGTH_SHORT).show();
}
});
from java-client.
Since you don't always want to run the done handler in the UI thread, you can do the following:
proxy.invoke("myMethod", "MyParameter")
.done(new Action<Void>() {
@Override
public void run(Void obj) throws Exception {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.i("DONE TEST", "DONE TEST");
Toast.makeText(context, "DONE TEST", Toast.LENGTH_SHORT).show();
}
});
}
}).onError(new ErrorCallback() {
@Override
public void onError(Throwable error) {
Toast.makeText(context, "ERROR TEST", Toast.LENGTH_SHORT).show();
}
});
from java-client.
I know it, but i don't like this way. I am happy with my callbacks :) You have to notice this way to other users because there is not a warning for UI thread. Thank you.
from java-client.
i try the way 1 (by handler),i can recieve the result, code as below:
hub.on("receiveHelloWorldReturn",
new SubscriptionHandler1() {
@OverRide
public void run(String msg) {
Log.i("0.03", "Result" + msg);
}
}, String.class);
hub.invoke("HelloWorldReturn");
But i try the way 2 ( direct ), i can't receive the result,
Class resultClass = null;
SignalRFuture str = hub.invoke(resultClass,
"HelloWorld2", "123");
str.done(new Action() {
@OverRide
public void run(String arg0) throws Exception {
Log.i("0.03", "arg0=" + arg0);
}
}).onError(new ErrorCallback() {
@OverRide
public void onError(Throwable error) {
Log.i("0.03", "error=" + error.toString());
}
});
could anyone help me how to recive the result by way 2?
or how to define the resultClass? thanks
from java-client.
You can find details in the Client Test code in the repository. But for brevity this is how you do it.
YourClass resultClass = new YourClass();
hub.invoke(resultClass.class, "HelloWorld2", "123")
.done(new Action() {
@OverRide
public void run(YourClass arg0) throws Exception {
// your code to access YourClass members
}
})
.onError(new ErrorCallback() {
@OverRide
public void onError(Throwable error) {
Log.i("0.03", "error=" + error.toString());
}
});
from java-client.
Related Issues (20)
- NullPointerExcepetion -> microsoft.aspnet.signalr.client.Connection.reconnect() HOT 5
- Custom Headers
- TCP Signal R Connection Issue HOT 1
- Android: NegotiationException: There was a problem in the negotiation with the server HOT 3
- Can't subscribe after reconnecting! HOT 5
- Asp.NetCore SignalR HOT 3
- Is this library dead ?! HOT 2
- android 4 connection issue HOT 1
- Deadlock HOT 1
- [Question] Support for Asp.net Core SignalR HOT 2
- Connection callbacks HOT 1
- SignalR Service Hang the app HOT 1
- how to get Connection ID in signalR
- Problem in getting Connection Id HOT 1
- Getting protocol Exception when trying to establish connection with auth header. HOT 1
- Is this library still maintained? HOT 2
- Getting exception randomly HOT 1
- Null Pointer Exception HOT 4
- Click on the URL in Question section return 404 HOT 1
- This repo is obsolete - please see the readme file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-client.