Last active
August 22, 2018 06:39
-
-
Save bapspatil/e441c4c584de183edf51b4f925a022cc to your computer and use it in GitHub Desktop.
MainActivity.java in app module for Android App Bundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Global instance of SplitInstallManager, needed to send the request to download the required module(s) | |
| private SplitInstallManager splitInstallManager = null; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| // Instantiate an instance of SplitInstallManager for the dynamic feature module | |
| splitInstallManager = | |
| SplitInstallManagerFactory.create(getApplicationContext()); | |
| } | |
| public void loadFeatureOne() { | |
| // Builds a request to install the feature1 module | |
| SplitInstallRequest request = | |
| SplitInstallRequest | |
| .newBuilder() | |
| // You can download multiple on demand modules per | |
| // request by invoking the following method for each | |
| // module you want to install. | |
| .addModule("feature1") | |
| .build(); | |
| // Begin the installation of the feature1 module and handle success/failure | |
| splitInstallManager | |
| .startInstall(request) | |
| .addOnSuccessListener(new OnSuccessListener<Integer>() { | |
| @Override | |
| public void onSuccess(Integer integer) { | |
| // Module download successful | |
| } | |
| }) | |
| .addOnFailureListener(new OnFailureListener() { | |
| @Override | |
| public void onFailure(Exception e) { | |
| // Module download failed; handle the error here | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment