目录

How do I ensure that preferences data can be properly read across modules and processes?

Answer

Cross-module interaction

Since the preference instance varies with the context, data may fail to be obtained in cross-module and cross-page scenarios. To solve this problem, use a singleton class to store a global context in Ability or use an application-level context.

Cross-process interaction

Generally, different processes can access a preferences file only in the same sandbox. You can use dataGroupId to share a preferences file across processes.