RT DB AddOnCompleteListener

Advertisements
 myRef.setValue("This is root node value").addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                
                if(task.isSuccessful()){
                    //Task was successful, data written!
                    Toast.makeText(MainActivity.this, "Data saved!", Toast.LENGTH_SHORT).show();
                }else{
                    //Task was not successful,
                    Toast.makeText(MainActivity.this, "Something went wrong", Toast.LENGTH_SHORT).show();
                    
                    //Log the error message
                    Log.e(TAG, "onComplete: ERROR: " + task.getException().getLocalizedMessage() );
                }

            }
        });