{"__v":5,"_id":"55a932afc8bd450d000dd1d6","category":{"__v":11,"_id":"55a93098cf45e1390093f351","pages":["55a930bdcf45e1390093f353","55a932afc8bd450d000dd1d6","55a938ba4c661b3700cf4e1f","55a939b502becf2d007aac34","55a93a015d3abb0d0012f184","55a93b225d3abb0d0012f191","55a93c4002becf2d007aac43","55a93d4c02becf2d007aac4c","55a940485d3abb0d0012f1af","55a9409802becf2d007aac64","55a9410c5d3abb0d0012f1b4"],"project":"559a61d2dbcfd20d00710b39","version":"559a61d2dbcfd20d00710b3c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-17T16:43:04.054Z","from_sync":false,"order":4,"slug":"android-sdk-reference","title":"Android SDK Reference"},"parentDoc":null,"project":"559a61d2dbcfd20d00710b39","user":"559a618bdbcfd20d00710b38","version":{"__v":23,"_id":"559a61d2dbcfd20d00710b3c","project":"559a61d2dbcfd20d00710b39","createdAt":"2015-07-06T11:09:06.510Z","releaseDate":"2015-07-06T11:09:06.510Z","categories":["559a61d3dbcfd20d00710b3d","55a589ddaaf9cf1900114dd0","55a589e30f354f0d00fd0312","55a589ea80c8a30d00b323cc","55a589f6aaf9cf1900114dd1","55a58d4e80c8a30d00b323e6","55a8e7a227a17d21005251a2","55a93098cf45e1390093f351","55afb085f202b12100cd9e83","55afb22e902fd51700f5f8bf","55afb260902fd51700f5f8c2","55afb28ec8a85321007a5462","55afb294f202b12100cd9e95","55afb29b902fd51700f5f8c5","55afb2a1c8a85321007a5463","55afb2a7902fd51700f5f8c7","55afb2ad902fd51700f5f8c8","55afb2b5902fd51700f5f8ca","55b74b2131bccb190081bedc","55bb441b54f9640d006e6cf2","565711085cb2420d00d70071","5681681330018c0d006bf7ff","588f38b5923d610f00c72dad"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"Version 1.0","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-17T16:51:59.713Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"- The app Instance object is a local representation of an app instance downloaded and installed in a user device. \n- The instance object is automatically managed by MOCA. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"MOCAInstance instance = MOCA.getInstance();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n- The instance object holds a collection of properties. Property-value pairs can be set and retrieved and are persisted between app sessions\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/*Returns true if this map contains a mapping for the specified key.*/\\ncontainsProperty(java.lang.String key)\\n\\n/*Returns the Object Array value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetArrayProperty(java.lang.String key)\\n\\n/*Returns the Boolean value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetBoolProperty(java.lang.String key)\\n\\n/*Returns the Float value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetFloatProperty(java.lang.String key)\\n  \\n/*Returns the Integer value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetIntegerProperty(java.lang.String key)\\n  \\n/*Returns the long value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetLongProperty(java.lang.String key)\\n  \\n/*Returns the value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetProperty(java.lang.String key)\\n\\n/*Returns the String Array value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetStringArrayProperty(java.lang.String key)\\n  \\n/*Returns the String value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\\ngetStringProperty(java.lang.String key)\\n\\n/*Gets existing property keys.*/\\npropertySet()\\n  \\n/*Associates the specified property value with the specified property key in this container.*/\\nsetProperty(java.lang.String key, java.lang.Object value)\\n\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThe instance object holds **predefined properties** collected automatically:\n\n- Device-oriented, including:\n - device_model – the device model (i.e. iPhone 4S, iPhone 5C, iPhone 5S)\n - device_type – the type of device (i.e. iPhone, iPad, Simulator)\n - local_timezone – the local time zone's abbreviated name (i.e. EDT, GMT, PST)\n - country – the country code as defined by the user in Settings\n - lang – the user preferred language code as defined in Settings\n - os_name – the OS name (i.e. “Android”)\n - os_version – the OS version (i.e. “4.4”)\n - carrier_name – the name of the user’s home cellular service provider (E.g. Vodafone)\n - carrier_country – the ISO country code for the user’s cellular service provider.\n- App-oriented, including:\n - app_name – the app name\n - app_version – the app version number\n - vendor_id – the unique identifier for app vendor (i.e. UUID string)\n - moca_version – the version of MOCA SDK\n - gcm_token – the push notification device token (optional)\n - session – session counter (how many times a user launched the app).\n\n\n- The object may also store any custom property-value pairs. \n- Each instance object is persisted both locally and in the cloud. The instance is automatically uploaded to the cloud each time the app starts.\n- The instance can be saved manually to the cloud. All saves are asynchronous.\n- It is recommended to perform as many sets as desired and then just invoke a single save operation.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"MOCAInstance instance = MOCA.getInstance ();\\n// set MOCA custom properties\\ninstance.setProperty(\\\"job_position\\\", \\\"CTO\\\");\\ninstance.setProperty(”user_identifier\\\", 2948579);\\ninstance.setProperty(”user_score\\\", 147.61);\\ninstance.setProperty(”last_timestamp\\\", System.currentTimeMillis());\\nString[] skills = new String[]{“NoSQL\\\", ”Ruby\\\", “Java\\\", ”Objective-C\\\"};\\ninstance.setProperty(”user_skills\\\", skills );\\n                     // asynchronously upload to cloud\\ninstance.save(new MOCACallback<MOCAInstance>() {\\n                :::at:::Override\\n                public void success(MOCAInstance mocaInstance) {\\n                    MLog.i(\\\"Instance uploaded to cloud\\\");\\n                }\\n\\n                @Override\\n                public void failure(MOCAException e) {\\n                    MLog.e(\\\"Instance upload failed\\\", e);\\n                }\\n});\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"instance-api-1","type":"basic","title":"Instance API"}
- The app Instance object is a local representation of an app instance downloaded and installed in a user device. - The instance object is automatically managed by MOCA. [block:code] { "codes": [ { "code": "MOCAInstance instance = MOCA.getInstance();", "language": "java" } ] } [/block] - The instance object holds a collection of properties. Property-value pairs can be set and retrieved and are persisted between app sessions [block:code] { "codes": [ { "code": "/*Returns true if this map contains a mapping for the specified key.*/\ncontainsProperty(java.lang.String key)\n\n/*Returns the Object Array value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetArrayProperty(java.lang.String key)\n\n/*Returns the Boolean value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetBoolProperty(java.lang.String key)\n\n/*Returns the Float value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetFloatProperty(java.lang.String key)\n \n/*Returns the Integer value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetIntegerProperty(java.lang.String key)\n \n/*Returns the long value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetLongProperty(java.lang.String key)\n \n/*Returns the value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetProperty(java.lang.String key)\n\n/*Returns the String Array value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetStringArrayProperty(java.lang.String key)\n \n/*Returns the String value to which the specified property key is mapped, or null if this map contains no mapping for the key.*/\ngetStringProperty(java.lang.String key)\n\n/*Gets existing property keys.*/\npropertySet()\n \n/*Associates the specified property value with the specified property key in this container.*/\nsetProperty(java.lang.String key, java.lang.Object value)\n\n", "language": "java" } ] } [/block] The instance object holds **predefined properties** collected automatically: - Device-oriented, including: - device_model – the device model (i.e. iPhone 4S, iPhone 5C, iPhone 5S) - device_type – the type of device (i.e. iPhone, iPad, Simulator) - local_timezone – the local time zone's abbreviated name (i.e. EDT, GMT, PST) - country – the country code as defined by the user in Settings - lang – the user preferred language code as defined in Settings - os_name – the OS name (i.e. “Android”) - os_version – the OS version (i.e. “4.4”) - carrier_name – the name of the user’s home cellular service provider (E.g. Vodafone) - carrier_country – the ISO country code for the user’s cellular service provider. - App-oriented, including: - app_name – the app name - app_version – the app version number - vendor_id – the unique identifier for app vendor (i.e. UUID string) - moca_version – the version of MOCA SDK - gcm_token – the push notification device token (optional) - session – session counter (how many times a user launched the app). - The object may also store any custom property-value pairs. - 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. [block:code] { "codes": [ { "code": "MOCAInstance instance = MOCA.getInstance ();\n// set MOCA custom properties\ninstance.setProperty(\"job_position\", \"CTO\");\ninstance.setProperty(”user_identifier\", 2948579);\ninstance.setProperty(”user_score\", 147.61);\ninstance.setProperty(”last_timestamp\", System.currentTimeMillis());\nString[] skills = new String[]{“NoSQL\", ”Ruby\", “Java\", ”Objective-C\"};\ninstance.setProperty(”user_skills\", skills );\n // asynchronously upload to cloud\ninstance.save(new MOCACallback<MOCAInstance>() {\n @Override\n public void success(MOCAInstance mocaInstance) {\n MLog.i(\"Instance uploaded to cloud\");\n }\n\n @Override\n public void failure(MOCAException e) {\n MLog.e(\"Instance upload failed\", e);\n }\n});\n", "language": "java" } ] } [/block]