WebContent


public final class WebContent implements 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

public final class WebContent.Builder

Builder for WebContent.

Public methods

final @NonNull T
@UiThread
<T extends WebContentView> attach(
    @NonNull Context context,
    @NonNull Function<@NonNull Context, @NonNull T> factory
)

Constructs a WebContentView bound to this WebContent.

void

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

final void

Detaches this WebContent from its current WebContentView.

Public methods

attach

Added in 1.0.0-alpha01
@UiThread
public final @NonNull T <T extends WebContentView> attach(
    @NonNull Context context,
    @NonNull Function<@NonNull Context, @NonNull T> factory
)

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
@NonNull Context context

The context to use to construct the View.

@NonNull Function<@NonNull Context, @NonNull T> factory

A function that creates a new WebContentView.

Returns
@NonNull 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
public void close()

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
public final void detach()

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.