• The app Instance object is a local representation of an app instance downloaded and installed in a user device. It contains the anonymous user profile.

  • The instance object is automatically managed by MOCA.

MOCAInstance instance = MOCA.getInstance();
  • The instance object holds a collection of properties. Property-value pairs can be set and retrieved and are persisted between app sessions.
/**
 * Sets the value for the given property name.
 * 
 * @param value Value to be set. It must belong to one of the accepted classes.
 * @param key Property name.
 */
 public void setProperty(String key, Object value);

 /**
 * Gets the value for the given property.
 *
 * @param key Property name.
 * @return Value associated with the key or <code>null</code> if none.
 */
 public Object getProperty(String key);
  • Each instance object is persisted both locally and in the cloud. The instance is automatically uploaded to the cloud each time the app starts.
  • The instance can be saved manually to the cloud. All saves are asynchronous.
  • It is recommended to perform as many sets as desired and then just invoke a single save operation.
MOCAInstance instance = MOCA.getInstance();
instance.setProperty("favorite-color", "red");
instance.setProperty("current-plan", "starter");
instance.save(new MOCACallback<MOCAInstance>() {
  @Override
  public void success(MOCAInstance responseType) {
    Log.i("moca-sample", "All ok!");
  }

  @Override
  public void failure(MOCAException error) {
    Log.e("moca-sample","Something went wrong!" );
  }
});