MicroStrategy ONE

Log Out Users When Status Changes Occur in Another Android App

If you have MicroStrategy Mobile and your own management app installed on the same Android device, you can logout user sessions in MicroStrategy Mobile when certain status changes occur in the management app.

Introduction

We provide the Logout API to logout all sessions. In the Logout API, you can provide a callback to perform other tasks after the logout is complete. Refer to the code sample below to expose the Logout API.

Copy
public class LogoutSDK {

    /**
     * This API is exposed for SDK usage.
     * It is used to logout from all the projects from the mobile configuration.
     * It will close all the sessions against iServer and unRegister push notification.
     * @param logoutCallback callback to invoke after logout success. It will be invoked from UI thread.
     */
    public static void logout(final LogoutCallback logoutCallback){..}
}

/**
 * Callback when logout finished. The call back functions will be invoked from UI thread.
 */
public interface LogoutCallback {

    /**
     * Action to invoke after logout finish. It will be invoked from UI Thread
     * @param success whether logout is success or failure
     */
    void onLogoutFinish(boolean success);
}

Example

In this example, there are two apps, the MicroStrategy Mobile SDK app and the other app. The other app lets the MicroStrategy Mobile SDK app logout when it is in a certain state. To achieve this, the other app sends a logout broadcast to MicroStrategy Mobile SDK app. Once the MicroStrategy Mobile SDK app receives the logout broadcast, it invokes the logout from inside the app.

  1. Use MicroStrategy Mobile SDK to create a BroadcastReceiver class to handle the broadcast.

    Copy
    public class LogoutReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
           LogoutSDK.logout(new LogoutCallback() {
                        @Override
                        public void onLogoutFinish(boolean success) {
                           // put post logout operation here
                        }
                    });
        }
    }

  2. Declare the above broadcast receiver class in the manifest and specify the action to match the intent action for the broadcast.

    Copy
    <receiver android:name="com.microstrategy.android.LogoutReceiver" android:exported="true"> <!-- replace the receiver class name with your own --> 
        <intent-filter>
            <action android:name="ACTION_NAME"/>
        </intent-filter>
    </receiver>
  3. In the other app, send out the broadcast to the logout receiver, when the other app hits certain state, to trigger logout in the MicroStrategy Mobile app. You need to have an activity or application context to send the broadcast.

    Copy
    public void sendLogoutBroadcast(Context context) {
        Intent i = new Intent();
        i.setAction(“ACTION_NAME");
        i.setClassName(“SDK_PACKAGE_NAME", "com.microstrategy.android.LogoutReceiver");
        context.sendBroadcast(i);
    }