Here I am writing the way to call cloud method from the code.
Below is the method in the parse cloud.
Parse.Cloud.define("testing_method", function(request, response) {
var textMsg = "Testing 1 2 3";
var jsonObject = {
"answerMsg": textMsg
};
response.success(jsonObject);
});
So now, we need to call this method from the client end.
Parse provide ParseCloud class to handle Parse cloud methods.
So We use callFunctionInBackground() method of ParseCloud to call the cloud functions.
The first param is the name of the function, second is the params. Because we don't need any param right now, So just pass null. Third is the return type.
ParseCloud.callFunctionInBackground("testing_method", null, new FunctionCallback< Map<String, Object> >() {
public void done(Map<String, Object> mapObject, ParseException e) {
if (e == null){
Toast.makeText(getApplicationContext(), mapObject.get("answerMsg").toString(), Toast.LENGTH_LONG).show();
}
}
});
Below is the example to call function by passing params
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("challengeId", mChallengeId);
ParseCloud.callFunctionInBackground("getChallenge", params, new FunctionCallback<Map<String, List<ParseObject>>>() {
public void done(Map<String, List<ParseObject>> mapObject, ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(), mapObject.get("answerMsg").toString(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Error "+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
1 Comment(s)