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.
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...34public class MainApplication extends Application{56 @Override7 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.
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
1override fun logout(frontActivity: Activity){2 // Clean up all persistent and non-persistent app artifacts3 // ...4 // Call superclass after doing your own cleanup5 super.logout(frontActivity)6}
Java
1@Override2 public void logout(Activity frontActivity) {3 // Clean up all persistent and non-persistent app artifacts4 // ...5 // Call superclass after doing your own cleanup6 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.
To 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.
We've Moved
Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.