Skip to content

Instantly share code, notes, and snippets.

@bapspatil
Last active August 22, 2018 06:39
Show Gist options
  • Save bapspatil/e441c4c584de183edf51b4f925a022cc to your computer and use it in GitHub Desktop.
Save bapspatil/e441c4c584de183edf51b4f925a022cc to your computer and use it in GitHub Desktop.
MainActivity.java in app module for Android App Bundle
// 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