0

我在整个应用程序中使用共享首选项。我有一个问题。我认为我的数据在后台丢失了。

SharedPreferences preferences = getSharedPreferences(pref_data, Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("isDriverLogin", "True");
editor.putString("driverPassword", driverPassword);
editor.putString("carrierId", carrierId);
editor.putString("CCTID", cctid);
editor.putString("shipment", entityShipment);
editor.putString("isAccepted", "");
editor.commit();

在应用程序的某处,我创建了另一个对象并仅编辑数据的一部分

SharedPreferences preferences = getSharedPreferences(pref_data, Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("isDriverLogin", "True");
editor.commit();

我在整个申请过程中都在这样做。只编辑一两个数据。但在某些时候,我的应用程序崩溃或没有发生预期的行为。这种行为取决于我的偏好数据。

我尝试通过仅创建一个共享首选项对象并始终使用所有数据对其进行编辑来修复它。例如,我有 5 个关于共享偏好的数据。如果我只需要编辑一个,我仍然会将一些数据放在另外 4 个上,以确保没有任何内容被覆盖。

你们有什么想法吗?

4

0 回答 0