【发布时间】:2018-04-10 16:12:25
【问题描述】:
我在我的 Android 应用程序中使用 Firebase 数据库已经快一年了,它工作得非常好。不幸的是,数据在一段时间后停止同步。它只是永远不会同步/存储到云中。仅限本地。因此,当用户重新安装应用程序时,它只包含存储在云中的数据。所以对用户来说,看起来数据已被删除,但实际上从未存储过。我检查了,数据在 firebase 控制台中不可见。因为它发生在重新安装后,我猜它与同步有关。用户报告丢失大约 2-3 个月的数据。
我正在使用以下单例助手类。注意我使用setPersistenceEnabled(true) 和keepSynced(true)。
public class FirebaseHelper{
protected FirebaseHelper(Context c) {
this.c = c.getApplicationContext();
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
mAuth = FirebaseAuth.getInstance();
this.userRef = FirebaseDatabase.getInstance().getReference().child(((BuildConfig.DEBUG ? "debug" : "release"))).child("users").child(getUID());
this.userRef.keepSynced(true);
this.path1 = userRef.child("path1");
this.path2 = userRef.child("path2");
this.path3 = userRef.child("path3");
this.path4 = userRef.child("path4");
}
public static FirebaseHelper getInstance(Context c) {
if (instance == null) {
instance = new FirebaseHelper(c);
}
return instance;
}
public String insertObject(MyObject obj) {
DatabaseReference newItem = this.path1.push();
String pushID = newItem.getKey();
obj.id = pushID;
newItem.setValue(obj.getObject());
return pushID;
}
public void updateData(...){}
...other methods
}
这可能是什么原因?
【问题讨论】:
-
不,这不是答案。它不需要几秒钟,它只是没有发生。当用户添加数据时,应用程序也会不时打开。
-
所以您是说用户重新安装后数据会从数据库中删除?
-
@AndréKool 它没有被删除。它只是永远不会同步/存储到云中。仅限本地。因此,当用户重新安装应用程序时,它只包含存储在云中的数据。所以对用户来说,数据看起来像是被删除了,但实际上从未存储过。
-
哇,如果数据没有存储数月,这听起来是个大问题。用户是否一直离线工作?您是否主动在应用中保存数据?我认为您可能应该重写您的问题,因为重新安装听起来不是问题,而是数据没有在线存储的事实。
标签: android firebase firebase-realtime-database