MicroStrategy ONE
Customize Startup Activity for Android
Library Mobile SDK for Android supports setting up your own startup activity to add specific operations before the app launches.
- Set up the environment to use the Library Mobile for Android project. You are using this project as the basis for your customizations.
- Next, let's create the interface. Open the project in Android Studio.
- Switch your Tool window to the Project perspective.
- Navigate to src > main.
-
Right-click the main folder and create a new directory named java, to hold all of your Java source files.
-
Under the java directory, create a new package named com.example.
-
Create a new java class named CustomizedStartupActivity under the package that extends the Activity interface.
-
Define your operations within the class.
-
After your customized operations are complete, create an intent to start MstrStartupActivity to launch the Library app.
Copyprivate void launchMstrApp() {
Intent intent = new Intent(this, MstrStartupActivity.class);
Uri uriData = getIntent().getData();
if(uriData != null) {
//If application launched with URL, you can pass the URL to MstrStartupActivity
intent.setData(uriData);
intent.setAction(android.content.Intent.ACTION_VIEW);
}
startActivity(intent);
} -
Navigate to src > main > AndroidManifest.xml. Replace the configuration of MstrStartupActivity to your CustomizedStartupActivity and set up MstrStartupActivity without intent-filter.
Expand to see your code prior to any changes.Copy<application...>
...
<activity android:configChanges="orientation|screenSize" android:launchMode="singleTop" android:name="com.microstrategy.android.ui.activity.MstrStartupActivity" android:theme="@style/MstrStartupActivityStyle" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="@string/external_url_scheme"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="@string/external_url_scheme"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
</activity>
...
</application>Expand to see your code after changes.Copy<application...>
...
<activity android:name="com.example.CustomizedStartupActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="@string/external_url_scheme"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="@string/external_url_scheme"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
</activity>
<activity android:configChanges="orientation|screenSize" android:launchMode="singleTop" android:name="com.microstrategy.android.ui.activity.MstrStartupActivity" android:theme="@style/MstrStartupActivityStyle" android:windowSoftInputMode="stateHidden"/>
...
</application> - Clean and rebuild the project.
The following code example uses CustomizedStartupActivity to display an alert dialog before the app launches. You can show this alert in the onCreate(Bundle savedInstanceState) method of the activity. The app launches after the user taps Continue to dismiss the alert.
public class CustomizedStartupActivity extends Activity implements DialogInterface.OnDismissListener {
AlertDialog alertDialog = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showAlertDialog("Welcome","Welcome to MicroStrategy Library");
}
private void launchMstrApp() {
Intent intent = new Intent(this, MstrStartupActivity.class);
Uri uriData = getIntent().getData();
if(uriData != null) {
//If application launched with URL, you can pass the URL to MstrStartupActivity
intent.setData(uriData);
intent.setAction(android.content.Intent.ACTION_VIEW);
}
startActivity(intent);
}
private void showAlertDialog(final String title, final String message){
final Context context = this;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message).setTitle(title);
alertDialog = builder.create();
alertDialog.setOnDismissListener(this);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
this.runOnUiThread(new Runnable() {
public void run() {
alertDialog.show();
}
});
}
public void onDismiss(DialogInterface var1) {
launchMstrApp();
}
}