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 |
addRule(@NonNull EmbeddingRule rule)Registers a new rule, or updates an existing rule if the |
final void |
Clears the rules previously registered by |
static final @NonNull RuleController |
getInstance(@NonNull Context context)Obtains an instance of |
final @NonNull Set<@NonNull EmbeddingRule> |
getRules()Returns a copy of the currently registered rules. |
static final @NonNull Set<@NonNull EmbeddingRule> |
parseRules(@NonNull Context context, @XmlRes int staticRuleResourceId)Parses |
final void |
removeRule(@NonNull EmbeddingRule rule)Unregisters a rule that was previously registered via |
final void |
setRules(@NonNull Set<@NonNull EmbeddingRule> rules)Sets a set of |
Public methods
addRule
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 |
clearRules
public final void clearRules()
Clears the rules previously registered by addRule or setRules.
getInstance
public static final @NonNull RuleController getInstance(@NonNull Context context)
Obtains an instance of RuleController.
getRules
public final @NonNull Set<@NonNull EmbeddingRule> getRules()
Returns a copy of the currently registered rules.
parseRules
public static final @NonNull Set<@NonNull EmbeddingRule> parseRules(@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
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 |
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 |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if |