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:
public static final void openH5(String url) {if (TextUtils.isEmpty(url)) {return;}H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext().findServiceByInterface(H5Service.class.getName());H5Bundle bundle = new H5Bundle();Bundle param = new Bundle();// The app ID of the offline package to be opened.param.putString(H5Param.APP_ID, appId);// The URL of the offline package to be opened, /www/index.html, in which the slash (/) must be added.// If no URL is transferred, the container opens the URL configured for the offline package by default.param.putString(H5Param.LONG_URL,url);bundle.setParams(param);if (h5Service != null) {H5Page h5Page=h5Service.createPage(activity,bundle);View view=h5Page.getContentView(),// The view is finally added to the page.}}
The codes of choosing asynchronous method to embed the view of a single container into the HTML5 page are as follows:
H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext().findServiceByInterface(H5Service.class.getName());H5Bundle bundle = new H5Bundle();Bundle param = new Bundle();param.putString(H5Param.APP_ID, appId);param.putString(H5Param.LONG_URL, url);bundle.setParams(param);if (h5Service != null) {h5Service.createPageAsync(activity, bundle, h5PageReadyListener);}