[英]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.