Android Template App: Deep Dive
To create new Android apps, the forcedroid create
command repurposes one of two Mobile SDK template projects. You can find both projects in the github.com/forcedotcom/SalesforceMobileSDK-Templates GitHub repo.
- AndroidNativeTemplate: Implements a basic Mobile SDK native app using Java.
- AndroidNativeTemplateKotlin: Implements a basic Mobile SDK native app using Kotlin.
To create specialized templates, use the forcedroid createwithtemplate
command.
- AndroidIDPTemplate: Demonstrates how to set up an identity provider in an Android app. When forcedroid createwithtemplate prompts for the repo URI, enter
AndroidIDPTemplate
. - MobileSyncExplorerKotlinTemplate: Provides a comprehensive example of Mobile Sync usage. When forcedroid createwithtemplate prompts for the repo URI, enter
MobileSyncExplorerKotlinTemplate
. - AndroidNativeLoginTemplate: Demonstrates how to set up native login. When forcedroid createwithtemplate prompts for the repo URI, enter
AndroidNativeLoginTemplate
.
By studying a template app, you can gain a quick understanding of native apps built with Mobile SDK for Android.
Template projects define two classes: MainApplication
and MainActivity
.
- The
MainApplication
class extends the AndroidApplication
class and callsMobileSyncSDKManager.initNative()
in itsonCreate()
override. - The
MainActivity
class extends theSalesforceActivity
class.
These two classes create a running mobile app that displays a login screen and a home screen.
Despite containing only about 200 lines of code, the Mobile SDK template apps are more than just “Hello World” examples. In its main activity, it retrieves Salesforce data through REST requests and displays the results on a mobile page. You can extend these apps by adding more activities, calling other components, and doing anything else that the Android operating system, the device, and your security constraints allow.