RuleController
class RuleController
The controller to manage EmbeddingRule
s. 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 companion functions |
|
---|---|
RuleController |
getInstance(context: Context) Obtains an instance of |
Set<EmbeddingRule> |
parseRules(context: Context, staticRuleResourceId: @XmlRes Int) Parses |
Public functions |
|
---|---|
Unit |
addRule(rule: EmbeddingRule) Registers a new rule, or updates an existing rule if the |
Unit |
Clears the rules previously registered by |
Set<EmbeddingRule> |
getRules() Returns a copy of the currently registered rules. |
Unit |
removeRule(rule: EmbeddingRule) Unregisters a rule that was previously registered via |
Unit |
setRules(rules: Set<EmbeddingRule>) Sets a set of |
Public companion functions
getInstance
fun getInstance(context: Context): RuleController
Obtains an instance of RuleController
.
parseRules
fun parseRules(context: Context, staticRuleResourceId: @XmlRes Int): Set<EmbeddingRule>
Parses EmbeddingRule
s from XML rule definitions.
The EmbeddingRule
s can then set by setRules
.
Parameters | |
---|---|
context: Context |
the context that contains the XML rule definition resources |
staticRuleResourceId: @XmlRes Int |
the resource containing the static split rules. |
Throws | |
---|---|
kotlin.IllegalArgumentException |
if any of the rules in the XML are malformed. |
Public functions
addRule
fun addRule(rule: EmbeddingRule): Unit
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 | |
---|---|
rule: EmbeddingRule |
new |
clearRules
fun clearRules(): Unit
Clears the rules previously registered by addRule
or setRules
.
getRules
fun getRules(): Set<EmbeddingRule>
Returns a copy of the currently registered rules.
removeRule
fun removeRule(rule: EmbeddingRule): Unit
Unregisters a rule that was previously registered via addRule
or setRules
.
Parameters | |
---|---|
rule: EmbeddingRule |
the previously registered |
setRules
fun setRules(rules: Set<EmbeddingRule>): Unit
Sets a set of EmbeddingRule
s, 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 EmbeddingRule
s can be parsed from parseRules
or built with rule Builders, which are:
Registering SplitRule
s 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 | |
---|---|
rules: Set<EmbeddingRule> |
The |
Throws | |
---|---|
kotlin.IllegalArgumentException |
if |