活动已泄漏窗口DecorView

时间:2019-01-27 19:15:42

标签: android firebase google-cloud-firestore

所以...我一直在尝试向Cloud Firestore中添加文件,并且在过去的3个小时中,我一直在研究为什么如果我做的所有事情都与我一样,我的progressdialog总是会泄漏窗口在其他活动中。我有一个将对象添加到数据库的按钮,并单击并快速验证,然后继续加载对话框(并且我尝试在代码中多次隐藏它,但仍然收到此错误)

    String stevilka_kartice = etStevilkaKartice.getText().toString().trim();
    String ime_trgovine = etImeTrgovine.getText().toString().trim();

    if(stevilka_kartice.isEmpty()) {
        etStevilkaKartice.setError(getResources().getString(R.string.stevilkaKarticeRequired));
        etStevilkaKartice.requestFocus();
        return;
    }

    if(ime_trgovine.isEmpty()) {
        etImeTrgovine.setError(getResources().getString(R.string.imeTrgovineRequired));
        etImeTrgovine.requestFocus();
        return;
    }

    FirebaseUser user = firebaseAuth.getCurrentUser();


    progressDialog.setMessage(getResources().getString(R.string.addingCard));
    progressDialog.show();

    Kartica k = new Kartica(user.getUid(), ime_trgovine, stevilka_kartice);
    k.setUrl_slike("https://firebasestorage.googleapis.com/v0/b/shoppingplus-5a575.appspot.com/o/kartice%2Fdefault_card.png?alt=media&token=5ea99819-8be6-4c61-845b-05879c1646c9");

    CollectionReference kartice = db.collection("kartice");
    kartice.add(k).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
        @Override
        public void onSuccess(DocumentReference documentReference) {
            progressDialog.hide();
            Toast.makeText(DopolnitevKarticeActivity.this, getResources().getString(R.string.cardAdded), Toast.LENGTH_SHORT).show();
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            progressDialog.hide();
            Toast.makeText(DopolnitevKarticeActivity.this, getResources().getString(R.string.cardNotAdded), Toast.LENGTH_SHORT).show();
        }
    });

    etStevilkaKartice.setText("");
    etImeTrgovine.setText("");

    finish();
    startActivity(new Intent(DopolnitevKarticeActivity.this, KarticeActivity.class));

我将hide方法放到对话框的所有内容之上(就在我完成此操作并进入karticeactivity之前),关闭,隐藏成功和失败的回调。出于某种原因,当我仅显示它而不隐藏它时,它就起作用了(但是如果它不被忽略,那将破坏目的)。一旦我把代码隐藏起来,它就会崩溃

0 个答案:

没有答案