简体   繁体   English

如何将共享偏好与 apk 链接?

[英]How to link shared preference with apk?

I build an android app where I'm using shared preference to store data.我构建了一个 android 应用程序,我在其中使用共享首选项来存储数据。 When I'm editing the data from the app it works fine for my device.当我从应用程序编辑数据时,它适用于我的设备。 But if I share the apk with another device, the data of shared preference for that device remains the default value, not the edited one.但是,如果我与另一台设备共享 apk,该设备的共享首选项数据仍为默认值,而不是编辑后的值。 So, what can I do to edit data from the app then share the apk with anothe device so that it gets the edited data?那么,我该怎么做才能从应用程序编辑数据,然后与另一个设备共享 apk 以便它获取编辑后的数据? (I'm very new to android) (我对安卓很陌生)

I think you have misunderstood the concept of Shared preference as it is used to store data inside app.我认为您误解了共享首选项的概念,因为它用于在应用程序内存储数据。

Shared preference is similar to local db.共享偏好类似于本地数据库。 It stores data like name-value pair.它存储名称-值对等数据。 Means it stores data in your app's internal storage permanently until you clear data or uninstall app.意味着它将数据永久存储在您应用程序的内部存储中,直到您清除数据或卸载应用程序。 If you want to share data between devices then use web server based on unique id for ex: device id of the phone.如果您想在设备之间共享数据,请使用基于唯一 ID 的 Web 服务器,例如:手机的设备 ID。

Shared Preferences are stored locally in each device, you can't do this like changing the value and then pass the apk and would get the updated value.共享首选项存储在每个设备的本地,您不能像更改值然后传递 apk 并获得更新的值那样执行此操作。

For this you need to store the required value in cloud or server, so each time you will get the updated value, which will be fetched from the server.为此,您需要将所需的值存储在云或服务器中,因此每次您都会获得更新的值,该值将从服务器获取。

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

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