Call a Function - Android SDK

The examples in this section demonstrate calling a simple function named sum that takes two arguments, adds them, and returns the result:

// sum: adds two numbers
exports = function(a, b) {
return a + b;

To execute a function from the Android SDK, use the getFunctions() method of the your App to retrieve a Functions manager. Pass the name and parameters of the function you would like to call to callFunction() or callFunctionAsync():

val appID = YOUR_APP_ID // replace this with your App ID
val app: App = App(AppConfiguration.Builder(appID).build())
val anonymousCredentials: Credentials = Credentials.anonymous()
app.loginAsync(anonymousCredentials) {
if (it.isSuccess) {
val user: User? = app.currentUser()
val functionsManager: Functions = app.getFunctions(user)
val args: List<Int> = listOf(1, 2)
functionsManager.callFunctionAsync("sum", args, { result ->
if (result.isSuccess) {
Log.v("EXAMPLE", "Sum value: ${result.get()}")
} else {
Log.e("EXAMPLE", "failed to call sum function with: " + result.error)
} else {
Log.e("EXAMPLE", "Error logging into the Realm app. Make sure that anonymous authentication is enabled. Error: " + it.error)
Give Feedback