Session

Native Android ==> Shared module

Overview

The "session" in the Validic Inform Mobile SDK is a crucial component for using the SDK's functionality. In the Native Android SDK, the session module is called "Shared". In the Native iOS SDK, the session module is called "Core".

The session stores a Validic user and all pending record uploads. The session also stores information necessary for various SDK operations, such as data permissions for Health Connect, peripheral information for Bluetooth, and more.

Important Considerations

Given the type of information that the session stores, you'll want to treat it very carefully and ensure that you only end the session when you no longer need any of that sort of information. Generally, the session is long-lived and is only ended when the user is no longer expected to have data records that need to be uploaded to Validic Inform.

So if you have functionality in your mobile app that lets the user log in and out, you'll want to consider whether you expect that user's data to still be collected and synced while they are logged out or not. If you want syncs to continue, you must keep the session alive with valid user credentials.

Another case to consider is if you have functionality in your app that auto-logs out users. Again, if you expect that data records will continue to sync then you must keep the session alive, otherwise data syncs will stop.

Lastly, if you do not want to force your user to re-select data sharing permissions with aggregators like Health Connect, then you must leave the session running. If the session is ended, granted data permissions are deleted from the SDK and the SDK will no longer be listening for data records. The user will have to re-grant data sharing permission in a new session in order for data syncs to start again. So always consider your user experience when you decide how to handle the session in your mobile app.

Implementation Details

SessionV2 a singleton object and must be accessed by its getInstance(context) method. The Session instance stores a Validic User and all pending InformRecord uploads. A valid session is required in order to use any of the modules in the Validic SDK.

A Validic user can be provisioned using the Validic API. Further documentation is available for the Inform API.

You will need to provision the user on your server. The mobile app could then authenticate to the server and retrieve the needed Validic credentials.

To use an existing Validic User, create a User object and provide it to the startSessionWithUser(User) method.

User user = new User("Your Organization ID",
                     "A Validic ID",
                     "A Validic User Mobile Access Token");

Session.getInstance(context).startSessionWithUser(user);

User data is persisted between app launches but is deleted if endSession() is called.

Session.getInstance().endSession();