Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

recover deleted child in firebase realtime database android

I need some help to undo deleted child, I already have the snackbar showing the undo onclick but I am not sure how to recover the child, I have it saved in ExpenseBackUp, but how do I get it back? any idea?

    delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Expenses").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
            reference.child(postId).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {


                Expense expenseBackUp = new Expense(item, category, date, postId, amount);

                @Override
                public void onComplete(@NonNull Task<Void> task) {


                    if (task.isSuccessful()) {
                        Snackbar.make(rv, item + " has been deleted", Snackbar.LENGTH_LONG).setAction("UNDO", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                //undo onClick actions
                                
                                Toast.makeText(ExpensesActivity.this, item+" recovered", Toast.LENGTH_SHORT).show();
                            }
                        }).show();

                    } else {
                        Toast.makeText(ExpensesActivity.this, "Something went wrong, try again" + task.getException(), Toast.LENGTH_SHORT).show();
                    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Are you looking for:

reference.child(postId).setValue(expenseBackUp)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading