MicroStrategy ONE

Customize the App Lifecycle for Android

Library Mobile SDK for Android supports callbacks for application state changes such as application launching, transitioning to the foreground or background, or application termination. You can customize the application lifecycle using the AppDelegate interface.

The following table lists the methods in com.microstrategy.android.AppDelegate:

Return Type

Method and Description

void

onApplicationWillFinishLaunchingWithIntent(Intent intent)

@param Intent intent intent is the reason that launches the application, such as launching a URL.

Called when users tap an icon or URL to launch the app.

void

onApplicationDidEnterForeground()

Called when app transitions to foreground. Foreground is a state where users can view and interact with the app.

void

onApplicationDidEnterBackground()

Called when the app transitions to background. Background means the app is running but cannot be viewed. This is typically triggered when the user taps the device's Home button.

void

onApplicationWillTerminate()

Called when the app is terminated by the user tapping the Back button.

Implement Your Own Application Delegate Logic

  1. Set Up the Library Mobile Project for Android. You are using this project as the basis for your customizations.
  2. Next, let's implement the AppDelegate interface. Open the project in Android Studio.
  3. Switch your Tool window to the Project perspective.
  4. Navigate to src > main.
  5. Right-click the main folder and create a new directory named java, to hold all of your Java source files.

  6. Under the java directory, create a new package named com.example.

  7. Create a new java class named CustomizedAppDelegate under the package that implements the AppDelegate interface.

  8. Implement the methods defined in the AppDelegate interface.

  9. Navigate to src > main > AndroidManifest.xml.
  10. Configure your customizedAppDelegate as a meta-data tag under the application tag. The key is com.microstrategy.android.applicationDelegate.

    Copy
    <application... >
        ...
        <meta-data android:name="com.microstrategy.android.applicationDelegate" android:value="com.example.CustomizedAppDelegate"/>
        ...
    </application>
  11. Clean and rebuild the project.

Important Points to Consider

  • Use the @Keep annotation on the custom AppDelegate and Custom Startup Activity to preserve its original name and prevent it from being minified in the release build.

  • If you implement the AppDelegate interface and write your own logic in onApplicationWillFinishLaunchingWithIntent, do not add anything that is too time-consuming, since it can block the main thread and startup activity creation. If you need to implement something time-consuming, it's better to create your own activity and add your logic as shown in Customize Startup Activity for Android

  • If you customize your own startup activity and you want to implement the AppDelegate callbacks, you need to modify the stackBottomActivity configuration in AndroidManifest.xml. Change the activity of the com.microstrategy.android.stackBottomActivity key to one at the bottom of the activity stack when the app is running, as shown below.

    Copy
    <application... >
        ...
        <meta-data android:name="com.microstrategy.android.applicationDelegate" android:value="com.example.CustomizedAppDelegate"/>
        <meta-data android:name="com.microstrategy.android.stackBottomActivity" android:value="com.microstrategy.android.CustomizedStartupActivity"/>
        ...
    </application>