In this tutorial, we will learn how to integrate the HealthStack Backend with your application using the provided classes and interfaces. The backend integration package is designed to help you easily manage user registration, health data synchronization, and task management.
Overview
The HealthStack Backend Integration package contains the following components:
BackendFacade: Facade that collects the interface required for integrating with the backend that stores health data.
BackendFacadeHolder: Singleton holder for the BackendFacade instance.
RegisterException and UserAlreadyExistsException: Exception classes for handling registration-related errors.
HealthDataSyncClient: Interface for syncing health data with the backend.
UserRegistrationClient: Interface for registering users with the backend.
TaskClient: Interface for managing tasks from the backend.
Additionally, there are multiple classes for representing user and task data:
User
ItemResult
TaskResult
TaskSpec
Setup
First, ensure that the HealthStack Backend Integration package is imported into your project. Add the following dependencies in your build.gradle file:
Replace VERSION with the latest available version of the package. We currently have two versions available: 0.9a, our alpha, and 0.9b, our beta. Find more information about the beta version here: https://central.sonatype.com/artifact/io.s-healthstack/backend-integration/0.9b.
Using BackendFacade
BackendFacade is the main entry point for working with the backend. It implements the following interfaces:
HealthDataSyncClient
UserRegistrationClient
TaskClient
Create an instance of BackendFacade by using the singleton instance provided by BackendFacadeHolder:
val backendFacade = BackendFacadeHolder.instance
You can now use the backendFacade instance to access methods for user registration, health data synchronization, and task management.
User Registration
To register a new user with the backend, use the registerUser method of the UserRegistrationClient interface:
val idToken = "idToken"
val user = User(userId = "userId", profile = "profile")
try {
backendFacade.registerUser(idToken, user)
} catch (e: UserAlreadyExistsException) {
// Handle the case when the user already exists
} catch (e: RegisterException) {
// Handle other registration errors
}
Replace "idToken" with a valid ID token obtained during user authentication, and provide the user's profile information as required.
Health Data Synchronization
To synchronize health data with the backend, use the syncHealthData method of the HealthDataSyncClient interface:
val idToken = "idToken"
val healthData = "healthData"
backendFacade.syncHealthData(idToken, healthData)
Replace "healthData" with the actual health data collected through the HealthStack HealthDataLink.
Task Management
To retrieve tasks from the backend, use the getTasks method of the TaskClient interface:
val idToken = "idToken"
val lastSyncTime = "lastSyncTime"
val endTime = "endTime"
val tasks = backendFacade.getTasks(idToken, lastSyncTime, endTime)
To upload a user's task execution result to the backend, use the uploadTaskResult method of the TaskClient interface:
Replace the placeholders with actual data from the task execution.
Working with TaskSpec and TaskResult
TaskSpec is a data class that represents the task received from the backend. It contains information about the task, its items, and the contents of each item. To create a TaskSpec instance, you can use the data received from the getTasks method:
Replace the placeholders with actual data from the backend.
TaskResult is a data class that represents the result of a task. It contains information about the user, the completed task, and the results of each item in the task. To create a TaskResult instance, you can use the data from the task execution:
Replace the placeholders with actual data from the task execution.
Conclusion
In this tutorial, we've covered how to integrate the HealthStack Backend with your application using the provided classes and interfaces. By following these steps, you can easily manage user registration, health data synchronization, and task management in your application.
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.