亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Firebase 自動刪除記錄

Firebase 自動刪除記錄

神不在的星期二 2023-06-21 13:41:15
當我嘗試插入具有唯一 ID 的新子項時,Firebase 會自動刪除前一個子項。這是我的數據庫結構:{  "users" : {    "EIG2NaC4Y2S5GCbeaKUdpkJgtvp2" : {      "email" : "[email protected]",      "mobile" : "79234792387",      "name" : "User",      "pets" : {        "-LnD1RPwaDILobsUxARh" : {          "name" : "PetName",          "pet_family" : "Dog"        }      }    }  }}這是將新子項插入到 pets 下的方法:public void addPet() {    final String petname = petName.getText().toString();    final String petfamily = petFamily.getSelectedItem().toString();    addPetButton.setEnabled(false);    final ProgressDialog progressDialog = new ProgressDialog(AddPetActivity.this, R.style.AppTheme_Dark_Dialog);    progressDialog.setIndeterminate(true);    progressDialog.setMessage("Adding "+petname+"...");    progressDialog.show();    new Handler().postDelayed(new Runnable() {        @Override        public void run() {            FirebaseUser user = mAuth.getCurrentUser();            String userKey = user.getUid();            String petKey = mDatabase.child("users").child(userKey).child("pets").push().getKey();            mDatabase.child("users").child(userKey).child("pets").setValue(petKey);            mDatabase.child("users").child(userKey).child("pets").child(petKey).child("name").setValue(petname);            mDatabase.child("users").child(userKey).child("pets").child(petKey).child("pet_family").setValue(petfamily);            progressDialog.dismiss();            Intent intent = new Intent(getApplicationContext(), NavActivity.class);            intent.putExtra("calling-activity","AddPetActivity");            startActivityForResult(intent, 0);        }    }, 3000);}當我執行代碼時,Firebase 創建新的子項,但 2 秒后他刪除了另一個。
查看完整描述

1 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

錯誤是:

mDatabase.child("users").child(userKey).child("pets").setValue(petKey);

嘗試刪除這一行


查看完整回答
反對 回復 2023-06-21
  • 1 回答
  • 0 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號