RuleController


public final class RuleController


The controller to manage EmbeddingRules. It supports:

Note that this class is recommended to be configured in androidx.startup.Initializer or android.app.Application.onCreate, so that the rules are applied early in the application startup before any activities complete initialization. The rule updates only apply to future android.app.Activity launches and do not apply to already running activities.

Summary

Public methods

final void

Registers a new rule, or updates an existing rule if the tag has been registered with RuleController.

final void

Clears the rules previously registered by addRule or setRules.

static final @NonNull RuleController

Obtains an instance of RuleController.

final @NonNull Set<@NonNull EmbeddingRule>

Returns a copy of the currently registered rules.

static final @NonNull Set<@NonNull EmbeddingRule>
parseRules(@NonNull Context context, @XmlRes int staticRuleResourceId)

Parses EmbeddingRules from XML rule definitions.

final void

Unregisters a rule that was previously registered via addRule or setRules.

final void

Sets a set of EmbeddingRules, which replace all rules registered by addRule or setRules.

Public methods

addRule

Added in 1.1.0
public final void addRule(@NonNull EmbeddingRule rule)

Registers a new rule, or updates an existing rule if the tag has been registered with RuleController. Will be cleared automatically when the process is stopped.

Registering a SplitRule may fail if the SplitController.splitSupportStatus returns false. If not supported, it could be either because androidx.window.WindowProperties.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED not enabled in AndroidManifest or the feature not available on the device.

Note that registering a new rule or updating the existing rule will not be applied to any existing split activity container, and will only be used for new split containers created with future activity launches.

Parameters
@NonNull EmbeddingRule rule

new EmbeddingRule to register.

clearRules

Added in 1.1.0
public final void clearRules()

Clears the rules previously registered by addRule or setRules.

getInstance

Added in 1.1.0
public static final @NonNull RuleController getInstance(@NonNull Context context)

Obtains an instance of RuleController.

Parameters
@NonNull Context context

the Context to initialize the controller with

getRules

Added in 1.1.0
public final @NonNull Set<@NonNull EmbeddingRulegetRules()

Returns a copy of the currently registered rules.

parseRules

Added in 1.1.0
public static final @NonNull Set<@NonNull EmbeddingRuleparseRules(@NonNull Context context, @XmlRes int staticRuleResourceId)

Parses EmbeddingRules from XML rule definitions.

The EmbeddingRules can then set by setRules.

Parameters
@NonNull Context context

the context that contains the XML rule definition resources

@XmlRes int staticRuleResourceId

the resource containing the static split rules.

Throws
kotlin.IllegalArgumentException

if any of the rules in the XML are malformed.

removeRule

Added in 1.1.0
public final void removeRule(@NonNull EmbeddingRule rule)

Unregisters a rule that was previously registered via addRule or setRules.

Parameters
@NonNull EmbeddingRule rule

the previously registered EmbeddingRule to unregister.

setRules

public final void setRules(@NonNull Set<@NonNull EmbeddingRule> rules)

Sets a set of EmbeddingRules, which replace all rules registered by addRule or setRules.

It's recommended to set the rules via an androidx.startup.Initializer, or android.app.Application.onCreate, so that they are applied early in the application startup before any activities appear.

The EmbeddingRules can be parsed from parseRules or built with rule Builders, which are:

Registering SplitRules may fail if the SplitController.splitSupportStatus returns false. If not supported, it could be either because androidx.window.WindowProperties.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED not enabled in AndroidManifest or the feature not available on the device.

Note that updating the existing rules will not be applied to any existing split activity container, and will only be used for new split containers created with future activity launches.

Parameters
@NonNull Set<@NonNull EmbeddingRule> rules

The EmbeddingRules to set

Throws
kotlin.IllegalArgumentException

if rules contains two EmbeddingRules with the same EmbeddingRule.tag.