gpt4 book ai didi

Android Firebase 在单个路径中检索所有数据并将其存储在 SQLite 中

转载 作者:行者123 更新时间:2023-11-30 00:39:52 28 4
gpt4 key购买 nike

如何检索单个路径中的所有数据并将其存储在 SQLite 中?我发现在 searchView 中过滤数据对我来说真的很困难,因此我想出了从 firebase 检索数据并将其存储在 SQLite 中以在 View 中过滤或搜索的想法。

我认为这是可能的,但最简单的方法是什么? it is the path

如何将每个“帐户”从 firebase 粘贴到 SQLite?

最佳答案

试试这个

// get currently logged in user uid
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

// you can do filtering here to make sure user object is not null

// get the data by using addListenerForSingleValueEvent
FirebaseDatabase.getInstance().getReference("Account/" + user.getUid)
.addListenerForSingleValueEvent(new ValueEventListener() {
... onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
// do SQLite insertion for each data here
}
}
...
});

I assume you are familiar with SQLite, so I don't include code about it there

我们使用 addListenerForSingleValueEvent() 因为它只从 Firebase 数据库请求一次数据。不同于 addValueEventListener()。这是 the official documentation


编辑

看来我理解错了,上面的代码是用来向Account/randomUserId请求数据的,但是op却要求向Account请求数据。所以我们不再需要获取 FirebaseUser,并将上面的行替换为:

FirebaseDatabase.getInstance().getReference("Account")
.add ...

关于Android Firebase 在单个路径中检索所有数据并将其存储在 SQLite 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42709084/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com