getSharedPreferences 中弃用 MODE_MULTI_PROCESS 的替代方法

Alternative for deprecated MODE_MULTI_PROCESS in getSharedPreferences

对于将已弃用的 MODE_MULTI_PROCESS 与 getSharedPreferences 一起使用,是否有任何替代方案?

请参阅 Android documentation, you should use a ContentProvider

This constant was deprecated in API level 23. MODE_MULTI_PROCESS does not work reliably in some versions of Android, and furthermore does not provide any mechanism for reconciling concurrent modifications across processes. Applications should not attempt to use it. Instead, they should use an explicit cross-process data management approach such as ContentProvider.

看看Tray。它直接旨在解决这个问题(以及其他一些具有共同偏好的问题)。

Tray 实际上实现了一个 ContentProvider 来存储首选项。目前它使用 SQlite 数据库,但 AFAIK 设计允许其他存储后端。