title: Firebase - retrieving data by value to an outside variable
body: <p>I have a question regarding Firebase Realtime database.</p>
  
  <p>I'm trying to do a bookmark option in my program, which allows the user to store his/her's favourite pages, however whenever I try to retrieve data from my firebase database, the data is restored after the method returns a value.</p>
  
  <pre><code>public static boolean checkIfBookmarked(final String title){
      final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
      final DatabaseReference userBookmarks = FirebaseDatabase.getInstance().getReference().child("users")
              .child(user.getUid()).child("bookmarks");
      final boolean[] exists = new boolean[1];
      userBookmarks.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              exists[0] = dataSnapshot.child(title).exists() ;
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
      return exists[0];
  }
  </code></pre>