34,333
edits
Changes
no edit summary
At this point, the project consists of a single activity which will serve as the entry point for the base module of the app. This base module will be responsible for requesting, installing and managing the dynamic feature module.
To demonstrate the use of dynamic features, the base activity will consist of a series of buttons which will allow the dynamic feature module to be installed, launched and removed. The user interface will also include a TextView object to display status information relating to the dynamic feature module. With these requirements in mind, load the ''activity_main.xml'' layout file into the layout editor, delete the default TextView object, and implement the design so that it resembles Figure 861-1 below.
To add a dynamic feature module to the project, select the ''File -> New Module...'' menu option and, in the resulting dialog, choose the Dynamic Feature Module option as shown in Figure 861-2:
From the Project tool window illustrated in Figure 861-5 above, it is clear that the dynamic feature module contains little more than a manifest file at this point. The next step is to add an activity to the module so that the feature actually does something when launched from within the base module. Within the Project tool window, right-click on the package name located under ''my_dynamic_feature -> java'' and select the ''New -> Activity -> Empty Activity ''menu option. Name the activity ''MyFeatureActivity'' and enable the ''Generate Layout File'' option but leave the ''Launcher Activity'' option disabled before clicking on the ''Finish'' button.
# On the confirmation screen, click on the ''Start Rollout to Internal Test'' button. The app will be listed as ''Pending publication''. Once it has been approved by Google (a process that can take anywhere from a few minutes to a few hours), the app is ready for testing.
Once the release has been rolled out for testing and been approved, notifications will be sent out to all users on the internal testing track asking them to opt in to the test track for the app. Alternatively, copy the Opt-in URL listed on the ''Manage testers'' screen and send it to the test users. Once the users have opted in, a link will be provided which, when opened on a device, will launch the Play Store app and open the download page for the DynamicFeature app as shown in Figure 861-8:
</pre>
Generate a new app bundle containing the changes, then return to the ''Release Management -> App Releases ''page for the app in the Google Play Console, click on the ''Manage ''button in the ''Internal test track'' section followed by the ''Create Release'' button as highlighted in Figure 861-9 below:
</pre>
Test that the listener code works by incrementing the version number information, generating and uploading a new release app bundle and rolling it out for testing. If a dynamic feature module is already installed on a device, attempts to download the module again will be ignored by the Play Core Library classes. To fully test the listener, therefore, the app must be uninstalled from within the Play Store app before installing the updated release. Of course, with the app removed there will be no Update button to let us know that the new release is ready to be installed. To find out which release the Play Store app will install, scroll down the app page to the ''Read More'' button, select it and check the Version field in the ''App Info'' section as highlighted in Figure 861-9 10 below:
Figure 1-11
Repeat the usual steps to increment the version number, build the new app bundle, upload it to Google Play and roll out for testing. Delete the previous release from the device, install the new release and attempt to perform the feature download to test that the confirmation dialog appears as shown in Figure 861-12 below: