All Products
Search
Document Center

Manage HTML5 pages

Last Updated: Aug 30, 2021

After opening an HTML5 offline package, you can choose synchronous method or asynchronous method to embed the view of a single container into the page.

Note: The asynchronous method does not occupy the main thread and therefore does not compromise the performance.

The codes of choosing synchronous method to embed the view of a single container into the HTML5 page are as follows:

 
  1. public static final void openH5(String url) {
  2. if (TextUtils.isEmpty(url)) {
  3. return;
  4. }
  5. H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
  6. .findServiceByInterface(H5Service.class.getName());
  7. H5Bundle bundle = new H5Bundle();
  8. Bundle param = new Bundle();
  9. // The app ID of the offline package to be opened.
  10. param.putString(H5Param.APP_ID, appId);
  11. // The URL of the offline package to be opened, /www/index.html, in which the slash (/) must be added.
  12. // If no URL is transferred, the container opens the URL configured for the offline package by default.
  13. param.putString(H5Param.LONG_URL,url);
  14. bundle.setParams(param);
  15. if (h5Service != null) {
  16. H5Page h5Page=h5Service.createPage(activity,bundle);
  17. View view=h5Page.getContentView(),
  18. // The view is finally added to the page.
  19. }
  20. }

The codes of choosing asynchronous method to embed the view of a single container into the HTML5 page are as follows:

 
  1. H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
  2. .findServiceByInterface(H5Service.class.getName());
  3. H5Bundle bundle = new H5Bundle();
  4. Bundle param = new Bundle();
  5. param.putString(H5Param.APP_ID, appId);
  6. param.putString(H5Param.LONG_URL, url);
  7. bundle.setParams(param);
  8. if (h5Service != null) {
  9. h5Service.createPageAsync(activity, bundle, h5PageReadyListener);
  10. }