繁体   English   中英

在 Intents 中传递 FirebaseFirestore 引用

[英]Pass FirebaseFirestore reference in Intents

我需要将一个集合的 FirebaseFirestore 引用从一个活动发送到另一个活动,第二个活动将用于添加文档。 我怎样才能做到这一点?

将文档的路径作为字符串传递,作为附加的意图。 您可以使用getPath()从DocumentReference获取路径,然后使用相同的字符串通过将其传递到FirebaseFirestore的document()方法来构建新的DocumentReference。

尝试使用 getPath() 然后将其传递给文档引用。

例子:

从参考中获取路径

String documentId = getSnapshots().getSnapshot(position).getReference().getPath();

                // Bring users to View Event when clicking on viewEventButton
                holder.viewEventButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view1) {
                        Intent intent = new Intent(getActivity(), ViewEventActivity.class);
                        intent.putExtra("documentId",documentId);
                        ((MainPageActivity) getActivity()).startActivity(intent);
                    }
                });

从字符串路径获取文档

        String documentId = getIntent().getStringExtra("documentId");
        String documentName = documentId.substring(documentId.lastIndexOf("/") + 1);

        // TODO how to reflect document path based on the event that users click on the app -> documentPath -> SharedPreferences from HomePage
        DocumentReference docRef = db.collection("Events").document(documentName);

暂无
暂无

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

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