[英]Connect users and Firebase Database
So I am keeping track of a users taps on the screen and I have the user sign up with their email. 所以我跟踪屏幕上的用户点击,我让用户注册他们的电子邮件。 However, when it comes to using the Firebase Database I am lost.
但是,在使用Firebase数据库时,我很遗憾。 I am not sure, how to save integers and then it load up when the user logs in. Can someone point me in the right direction?
我不确定,如何保存整数然后在用户登录时加载。有人能指出我正确的方向吗?
I have watched a ton of videos and none show how to store information with an integer. 我观看过大量视频,但没有显示如何使用整数存储信息。
You don't need to do anything special for storing a integer or any other value in the Firebase DB. 在Firebase DB中存储整数或任何其他值时,您无需执行任何特殊操作。
You can use the uid of the current user and store the pojo/model directly into the the firebase DB. 您可以使用当前用户的uid并将pojo / model直接存储到firebase数据库中。
For example, this can be your java model class: 例如,这可以是您的java模型类:
public class Model {
private int tapCount=0;
public int getTapCount() {
return tapCount;
}
public void setTapCount(int tapCount) {
this.tapCount = tapCount;
}
}
When you want to insert the tap count into the Firebase db. 如果要将点按计数插入Firebase数据库。 You need to take the previous tap counts and add it with the current count update/create the Model object and set it into the Firebase db in the uid.
您需要获取先前的点击计数并将其与当前计数更新/创建Model对象一起添加,并将其设置为uid中的Firebase数据库。
FirebaseDatabase.getInstance().getReference()
.child("user")
.child(FirebaseAuth.getInstance()
.getCurrentUser()
.getUid())
.setValue(model);
This code will insert the model under the user key
and under user unique id
. 此代码将在
user key
和user unique id
下插入模型。
Thanks, 谢谢,
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.