WebContent


class WebContent : AutoCloseable


WebContent can attach and detachs to outlive Activity lifetimes.

To detach the active view so that its context can be safely garbage collected, call detach. To permanently destroy the engine and all associated resources, call close.

This may only be used when WebFeature.WEB_CONTENT feature checks pass.

Summary

Nested types

Builder for WebContent.

Public functions

T
@UiThread
<T : WebContentView> attach(context: Context, factory: Function<Context, T>)

Constructs a WebContentView bound to this WebContent.

open Unit

Permanently closes and destroys the underlying WebContentView engine associated with this WebContent.

Unit

Detaches this WebContent from its current WebContentView.

Public functions

attach

Added in 1.0.0-alpha01
@UiThread
fun <T : WebContentView> attach(context: Context, factory: Function<Context, T>): T

Constructs a WebContentView bound to this WebContent. This allows the underlying web engine, including its state, settings, and clients (such as android.webkit.WebViewClient and android.webkit.WebChromeClient), to outlive the view's lifetime. Previously bound WebContentView instances are destroyed when this method is called.

The provided context must be used to construct the WebContentView, and any previously attached WebContentView must be removed from the view hierarchy before calling this method.

detach must be called when this WebContentView is no longer in use to prevent context leaks. When the content is permanently retired, call close.

Parameters
context: Context

The context to use to construct the View.

factory: Function<Context, T>

A function that creates a new WebContentView.

Returns
T

A wrapped factory that automatically attaches this WebContent state.

Throws
IllegalArgumentException

if context is not an Activity context.

IllegalStateException

if a previously bound WebContentView is still in the view hierarchy, if the returned view uses a different context, or if this WebContent is closed.

close

Added in 1.0.0-alpha01
@UiThread
open fun close(): Unit

Permanently closes and destroys the underlying WebContentView engine associated with this WebContent. This method must be called from the main thread. Once closed, this WebContent instance can no longer be used.

detach

Added in 1.0.0-alpha01
@UiThread
fun detach(): Unit

Detaches this WebContent from its current WebContentView. Any callbacks triggered will return a DetachedWebContentView in this state.

The currently attached WebContentView must be removed from the view hierarchy before this method is called.

Throws
IllegalStateException

if the current WebContentView is still in the view hierarchy.