The Andriod SDK doc only shows the code examples using Async.executeAsync
What I want to do now is to call three device.getVariable("…") in a row, therefore I bet the best way would be to implement my own AsyncTask that wraps a sequence of API calls, because in this way I can also better handle the progressdialog on my UI.
Could anyone show me how I can properly call device.getVariable("…") and get the return value without following the Async.executeAsync code sample?
The Async class is entirely optional; it’s just a convenience.
The SDK very intentionally exposes blocking APIs, to make it easy to do things like making several calls in a row, but this also means you can’t call them from the main thread (Android rightly disallows network calls on the main thread!). However, you can making calls off the main thread via whatever approach works best (the Async class, AsyncTasks, raw Threads, whatever). Once you’re off the main thread, you can do whatever you want with the SDK methods!
Hi @rwmobi, I am trying to do the same as I ran into problem while device is offline. So I want to try sync call method with timeout too. Do u have success and able to share the calling method ?
This is what I tried but got "ParticleCloudException"
This is declare in same activity class -- ParticleDevice Dev;
public String getSparkVariableWait(final String name) {
Object result=0;
I finally got this working. Info for newbie like me : Android does not allow these network call in foreground (Activity). So in order to perform sync call, it require to open a new Thread.
new Thread() {
@Override
public void run() {
// Make the Particle CAll here
getSparkVariableWait("VariableName");
}
}.start();