简体   繁体   English

在Android上的用户个人资料之间共享首选项的最佳方法

[英]Best way to share preferences between user profiles on Android

I'm trying to port our app to run on a vendor's tablet, which uses Android's multiple user profiles . 我正在尝试将我们的应用程序移植到使用Android的多个用户个人资料的供应商的平板电脑上。 This creates a problem, because each time a profile is created, our app goes into setup mode (because the SharedPreferences aren't setup yet). 这就产生了一个问题,因为每次创建配置文件时,我们的应用都会进入设置模式(因为尚未设置SharedPreferences)。 I'd like to have the administrator profile set up the app once, and all other profiles will just load this configuration. 我想让管理员配置文件一次设置该应用程序,所有其他配置文件都将加载此配置。

SharedPreferences doesn't seem to work, so what's the best way of doing this? SharedPreferences似乎不起作用,那么最好的方法是什么?

You can save your preferences to a file. 您可以将首选项保存到文件中。 I would make an object, then convert it to json, and finaly save the json to a file. 我将创建一个对象,然后将其转换为json,最后将json保存到文件中。 When loading the app I would take the file and read the json back to an object. 加载应用程序时,我将获取文件并将json读回一个对象。 BTW: shared preferences is a xml file located on your device. 顺便说一句:共享首选项是位于设备上的xml文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM