MicroStrategy ONE

Customize the App Lifecycle in Android

You can replace the out-of-the box app delegate to customize the app lifecycle for Android. This can include implementing a custom login workflow.

MicroStrategy supports callbacks for the following application state changes:

Callback State Change
onApplicationWillTerminate() Termination: The app is terminated by the user tapping the Back button
onApplicationWillFinishLaunchingWithIntent(Intent) Launch Time: Users tap an icon or URL to launch the app. Intent is the reason why the app is launched.
onApplicationDidEnterForeground() Transitioning to the foreground: The app enters a state where users can view and interact with the app.

onApplicationDidEnterBackground()

Transitioning to the background: The app is running, but cannot be viewed in the foreground state. This is typically triggered when the user taps the device's Home button.

The AppDelegate interface is shown below.

Copy
public interface AppDelegate {
    /** This function is called when app is launched before launch activity is created. 
        @param Intent intent: intent that launch the application would be passed here as parameter.
        Note: Customer could get launch url from this method.
    */
    public void onApplicationWillFinishLaunchingWithIntent(Intent intent); 


    // This function is called when app just enter foreground.
    public void onApplicationDidEnterForeground();
    
    
    // This function is called when app just enter background.
    public void onApplicationDidEnterBackground();


    /** This function is called when application will be terminated.
        Note: When we say "will terminate", it means when the last activity on the bottom of the system stack will be removed.
    */
    public void onApplicationWillTerminate();
}

Implement the AppDelegate Interface

  1. Create a CustomizedAppDelegate that implements the AppDelegate interface.

    Copy
    package com.example;

    import android.content.Intent;
    import android.net.Uri;
    import android.util.Log;

    import com.microstrategy.android.AppDelegate;


    public class CustomizedAppDelegate implements AppDelegate{
        @Override
        public void onApplicationWillFinishLaunchingWithIntent(Intent intent) {
            Log.i("LifeCycle", "applicationWillFinishLaunching");
            if (null != intent) {
                Uri uri = intent.getData();
                if (uri == null) {
                    return;
                } else{
                    // Your own logic using uri
                }
            }
        }

        @Override
        public void onApplicationDidEnterForeground() {
            Log.i("LifeCycle", "applicationDidEnterForeground");
            //Your own logic when application enters foreground
        }

        @Override
        public void onApplicationDidEnterBackground() {
            Log.i("LifeCycle", "applicationDidEnterBackground");
            //Your own logic when application enters background
        }

        @Override
        public void onApplicationWillTerminate() {
            Log.i("LifeCycle", "applicationWillTerminate");
            //Your own logic when application will Terminate
        }
    }
  2. Configure your customizedAppDelegate in Manifest.xml as a meta-data tag under the application tag. The key is com.microstrategy.android.applicationDelegate.

  3. Copy
    <application android:allowBackup="false" android:hardwareAccelerated="true" android:icon="@drawable/mstr_icon" android:label="@string/app_name" android:largeHeap="true" android:logo="@drawable/mstr_logo" android:name="com.microstrategy.android.MstrApplication" android:resizeableActivity="false" android:theme="@style/MSTRNativeTheme" tools:replace="android:allowBackup, android:theme">
        ......
        <meta-data android:name="com.microstrategy.android.applicationDelegate" android:value="com.example.CustomizedAppDelegate"/>
        ......
    </application>

Important Points to Consider

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 in Android

If you customize your own startup activity and you want to implement the AppDelegate callbacks, you need to modify the stackBottomActivity configuration in manifest.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>