0

I am new to firebase .I started loading data into realtime database .It works fine but when i want to retrieve data from realtime database the data is restored from database but the code after the retrieval is not working.In the below case i can't see the Log "exited all yes" .Why is this happening?Since I am using singlevalue event i need not close the reference right?

FirebaseDatabase fire=FirebaseDatabase.getInstance();
            DatabaseReference ref=fire.getReference("Users/"+userid+"/hisnumber");
            ref.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {

                    se1 = (String) dataSnapshot.getValue();
                    System.out.println(se1);
                }

                @Override
                public void onCancelled(@NonNull DatabaseError error) {
                    System.out.println("The read failed: " + error.getCode());

                }
            });
            ref=fire.getReference("Users/"+userid+"/hisname");
            ref.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {

                    se2 = (String) dataSnapshot.getValue();
                    System.out.println(se2);
                }

                @Override
                public void onCancelled(@NonNull DatabaseError error) {
                    System.out.println("The read failed: " + error.getCode());

                }
            });
            Log.d("exited all","yes");
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Rocky
  • 41
  • 4
  • The `Log.d("exited all","yes")` will happen before the `System.out.println(se1)` and `System.out.println(se2)`, so you'll need to scroll up in your logcat output to find it. For why that is, see: https://stackoverflow.com/questions/50434836/getcontactsfromfirebase-method-return-an-empty-list/50435519#50435519 – Frank van Puffelen Aug 04 '20 at 13:56
  • yeah the problem is solved thanks. – Rocky Aug 07 '20 at 05:19

0 Answers0