SalesforceSDKManager Class
- Login and logout
- Passcodes
- Encryption and decryption of user data
- String conversions
- User agent access
- Application termination
- Application cleanup
initNative() Method
During startup, you initialize the MobileSyncSDKManager class object by calling its static initNative() method. This method takes the following arguments:
| Parameter Name | Description |
|---|---|
|
applicationContext |
An instance of Context that describes your application’s context. In an Application extension class, you can satisfy this parameter by passing a call to getApplicationContext(). |
|
mainActivity |
The descriptor of the class that displays your main activity. The main activity is the first activity that displays after login. |
Here’s an example from the MainApplication class of the forcedroid Java template app:
1import com.salesforce.androidsdk.mobilesync.app.MobileSyncSDKManager;
2...
3
4public class MainApplication extends Application {
5
6 @Override
7 public void onCreate() {
8 super.onCreate();
9 MobileSyncSDKManager.initNative(getApplicationContext(),
10 MainActivity.class);
11 ...
12 }
13}In this example, NativeKeyImpl is the app’s implementation of KeyInterface. MainActivity subclasses SalesforceActivity and is designated here as the first activity to be called after login.
1class MainApplication : Application() {
2 companion object {
3 private const val FEATURE_APP_USES_KOTLIN = "KT"
4 }
5
6 override fun onCreate() {
7 super.onCreate()
8 MobileSyncSDKManager.initNative(applicationContext, MainActivity::class.java)
9 MobileSyncSDKManager.getInstance().registerUsedAppFeature(FEATURE_APP_USES_KOTLIN)
10 ...
11 }
12}logout() Method
The SalesforceSDKManager.logout() method clears user data. For example, if you’ve introduced your own resources that are user-specific, you can override logout() to keep those resources from being carried into the next user session. SmartStore, the Mobile SDK offline database, destroys user data and account information automatically at logout.
Always call the superclass logout method somewhere in your method override, preferably after doing your own cleanup. Here’s an example of how to override logout().
- Kotlin
-
1override fun logout(frontActivity: Activity) { 2 // Clean up all persistent and non-persistent app artifacts 3 // ... 4 // Call superclass after doing your own cleanup 5 super.logout(frontActivity) 6} - Java
-
1@Override 2public void logout(Activity frontActivity) { 3 // Clean up all persistent and non-persistent app artifacts 4 // ... 5 // Call superclass after doing your own cleanup 6 super.logout(frontActivity); 7}
getLoginActivityClass() Method
This method returns the descriptor for the login activity. The login activity defines the WebView through which the Salesforce server delivers the login dialog.
getUserAgent() Methods
Mobile SDK builds a user agent string to publish the app’s versioning information at runtime. For example, the user agent in Mobile SDK 7.1 takes the following form.
1SalesforceMobileSDK/<salesforceSDK version> android mobile/<android OS version>
2(<device model>) <appName>/<appVersion> <appType with qualifier>
3<device ID> <list of features>The list of features consists of one or more two-letter descriptors of Mobile SDK features. Here’s a typical example.
1SalesforceMobileSDK/7.1.0 android mobile/9.0 (Pixel 3) RestExplorer/5.0 HybridRemote uid_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ftr_MU.AI.BWTo retrieve the user agent at runtime, call the SalesforceSDKManager.getUserAgent() method.
isHybrid() Method
Imagine that your Mobile SDK app creates libraries that are designed to serve both native and hybrid clients. Internally, the library code switches on the type of app that calls it, but you need some way to determine the app type at runtime. To determine the type of the calling app in code, call the boolean SalesforceSDKManager.isHybrid() method. True means hybrid, and false means native.