The Salesforce Developers website will undergo maintenance on May 29, 2024 from 3:00 a.m. UTC to 10:00 a.m. UTC. The maintenance process may affect the availability of our documentation. Please plan accordingly.

SalesforceSDKManager Class

The SalesforceSDKManager class is the entry point for all native Android applications that use Salesforce Mobile SDK. It provides mechanisms for:

  • Login and logout
  • Passcodes
  • Encryption and decryption of user data
  • String conversions
  • User agent access
  • Application termination
  • Application cleanup

Instead of calling SalesforceSDKManager directly, the forcedroid native template uses a subclass, MobileSyncSDKManager, to initialize apps.

During startup, you initialize the MobileSyncSDKManager class object by calling its static initNative() method. This method takes the following arguments:

Parameter NameDescription
applicationContextAn 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().
mainActivityThe 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:

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.

The Kotlin template app additionally defines a Kotlin-related constant and registers Kotlin as a used feature.

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

Java

This method returns the descriptor for the login activity. The login activity defines the WebView through which the Salesforce server delivers the login dialog.

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.

The list of features consists of one or more two-letter descriptors of Mobile SDK features. Here’s a typical example.

To retrieve the user agent at runtime, call the SalesforceSDKManager.getUserAgent() 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.