我正在使用Firebase
Firestore 我想要从数据库中移除数据...正在调整数据,但我的进度对话框已经卡住了。我想我必须使用工作线程,但是我不知道如何使用。
db = FirebaseFirestore.getInstance();
db.collection("expenses").document(ids)
.delete()
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(Expense_Summary.this, "successfully deleted file", Toast.LENGTH_SHORT).show();
result = "deleted";
hideProgressDialog();
finish();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("deleting f", "Error deleting document", e);
hideProgressDialog();
Toast.makeText(Expense_Summary.this, "Error deleting file", Toast.LENGTH_SHORT).show();
}
});
我提到了doc: https://firebase.google.com/docs/firestore/manage-data/delete-data
答案 0 :(得分:1)
试试这个:
final ProgressDialog progressDialog = ProgressDialog.show(Activity_name_here.this,"Please wait","Processing",true);
Runnable runnable=new Runnable() {
@Override
public void run() {
progressDialog.cancel();
}
};
Handler pdCanceller = new Handler();
pdCanceller.postDelayed(runnable, 3000);
db = FirebaseFirestore.getInstance();
db.collection("expenses").document(ids)
.delete()
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(Expense_Summary.this, "successfully deleted file", Toast.LENGTH_SHORT).show();
result = "deleted";
progressDialog.dismiss();
finish();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("deleting f", "Error deleting document", e);
progressDialog.dismiss();
Toast.makeText(Expense_Summary.this, "Error deleting file", Toast.LENGTH_SHORT).show();
}
});
使用上面的代码进度对话框将显示文本请等待,并在其旁边写一个小圆圈正在处理。
这个:pdCanceller.postDelayed(runnable, 3000);
指定我在这里使用3000毫秒的时间示例。然后,如果成功,将取消进度对话框。或者如果失败也会取消进度对话框。