Answers to common questions about using HTML5 containers in Android, including JSAPI customization, plugin scopes, offline package signature verification, and progress bar behavior.
What is the difference between interceptEvent and handleEvent when you customize a JSAPI?
Use interceptEvent to listen for other events from the container. Use handleEvent if the event is handled only by your plugin, and return true.
Returning true stops the event from propagating. Returning false allows it to continue propagating to other plugins.
When customizing a JSAPI, if an event is added with config.setEvents("event");, why must it also be added in the plugin's onPrepare method?
Container plugins are lazy-loaded, meaning they are loaded only when a page is created. The external config.setEvents method injects the event names to listen for, but the plugin object is not instantiated until a JS call occurs. Event dispatching for the instantiated plugin is handled by the plugin's internal onPrepare event. Therefore, you must ensure that the event specified in config.setEvents("event") is also specified in the internal onPrepare method.
What is the difference between the page, session, and service scopes when registering a custom JSAPI plugin?
The page scope corresponds to a WebView. The session scope corresponds to an App object in an mPaaS application. The service scope is a global singleton.
-
If you register the plugin with the page scope, a new plugin instance is created each time a WebView is created. The plugin's onRelease method is called when the WebView is destroyed.
-
If you register the plugin with the session scope, a new plugin is created each time an App object is created.
-
If you register the plugin with the service scope, the plugin is created only once. This happens the first time the container is opened.
Does signature verification check the source of an offline package, or does it perform an integrity check?
Signature verification performs both source validation and an integrity check. On the offline package publishing platform, if you configure a private signing key, the platform includes signature information in the downloaded .amr file. This signature is the ciphertext obtained by encrypting the offline package's hash value with the private key. During verification, the public key pre-configured in your project decrypts the ciphertext to retrieve the original hash value. The verification succeeds if this value matches the hash calculated from the local offline package.
This process ensures both the integrity of the offline package and the authenticity of its source.
Why can't the progress bar be hidden when opening an offline package?
This issue can occur if a resource fails to load offline, causing the page to fall back to online mode. In fallback mode, the H5 container restricts progress bar control, making it impossible to hide the loading progress bar by setting the SHOW_PROGRESS startup parameter.