Skip to main content

Usage: User initialization

Set and configure a user for data synchronization.

Update userID

Update the userID:

val result = rookConfigurationManager.updateUserID(userID)

result.fold(
{
// userID updated successfully
},
{
// Error updating userID

val error = when (it) {
is SDKNotInitializedException -> "SDKNotInitializedException: ${it.message}"
is TimeoutException -> "TimeoutException: ${it.message}"
else -> "${it.message}"
}
}
)
info

Any call to updateUserID with a different userID will override the previous userID and reset the sync status, so if you are using Yesterday sync all health data will synchronize again the next time the app is launched.

Login / Logout

The updateUserID function should be called as part of your login and initialization process. When your users logout from your app, you'll have two options:

  1. Call clearUserID to remove the userID from SDK.
  2. deleteUserFromRook to remove the userID from SDK and disable it in server (Only disable from Health Connect and Android data sources).

If you have previously called updateUserID and the app is restarted (closed and opened), you won't have to call updateUserID again.

After initializing, call getUserID to verify that the userID was autoconfigured ( recovered from preferences).

// Initialize SDK

val userID = rookConfigurationManager.getUserID()

if (userID != null) {
// userID was autoconfigured (recovered from preferences), no need to call rookConfigurationManager.updateUserID()
} else {
// userID wasn't autoconfigured (recovered from preferences), MUST call rookConfigurationManager.updateUserID()
}

User timezone

Every time updateUserID completes successfully, the timezone information will be updated. You can see the result of the operation in the logs. On success, you will see Timezone information updated; otherwise, you will see Failed to update timezone information with error:.

In most cases, the above behavior is sufficient. If you need to update the timezone information manually, call syncUserTimeZone:

val result = rookConfigurationManager.syncUserTimeZone()

result.fold(
{
// User timezone updated successfully
},
{
val error = when (it) {
is SDKNotInitializedException -> "SDKNotInitializedException: ${it.message}"
is UserNotInitializedException -> "UserNotInitializedException: ${it.message}"
is TimeoutException -> "TimeoutException: ${it.message}"
is HttpRequestException -> "HttpRequestException: ${it.message}"
else -> "${it.message}"
}

// Error updating user timezone
}
)