Changes

Jump to: navigation, search

A Kotlin Android Studio Dynamic Feature Tutorial

16 bytes removed, 13:56, 24 May 2019
no edit summary
== Implementing the launchIntent() Method ==
With the project structure and user interface designs completed it is time to use the Play Core Library to begin working with the dynamic feature module. The first step is to implement the ''launchFeature('') method, the purpose of which is to use an intent to launch the dynamic feature activity. Attempting to start an activity in a dynamic feature module that has yet to be installed, however, will cause the app to crash. The ''launchFeature() ''method, therefore, needs to include some defensive code to ensure that the dynamic feature has been installed. To achieve this, we need to create an instance of the SplitInstallManager class and call the ''getInstalledModules() ''method of that object to check whether the ''my_dynamic_feature'' module is already installed. If it is installed, the activity contained in the module can be safely launched, otherwise a message needs to be displayed to the user on the status TextView. Within the ''MainActivity.''''kt'' file, make the following changes to the class:
<pre>
== Implementing the installFeature() Method ==
The ''installFeature()'' method will create a SplitInstallRequest object for the ''my_dynamic_feature'' module, then use the SplitInstallManager instance to initiate the installation process. Listeners will also be implemented to display Toast messages indicating the status of the install request. Remaining in the ''MainActivity.''''kt'' file, add the ''installFeature()'' method as follows:
<pre>
== Adding the Update Listener ==
For more detailed tracking of the installation progress of a dynamic feature module, an instance of SplitInstallStateUpdatedListener can be added to the app. Since it is possible to install multiple feature modules simultaneously, some code needs to be added to keep track of the session IDs assigned to the installation processes. Begin by adding some imports, declaring a variable in the ''MainActivity.''''kt'' file to contain the current session ID and modifying the ''installFeature()'' method to store the session ID each time an installation is successfully started and to register the listener:
<pre>
== Removing a Dynamic Module ==
The final task in this project is to implement the ''deleteFeature()'' method as follows in the ''MainActivity.''''kt'' file:
<pre>

Navigation menu