title: Firebase Realtime Database long values always return 0 even though it is not
body: <p>I have been trying to search for a solution for quite some time, but to no avail. I am clearly not a Firebase expert and am still learning how to code.</p>
  
  <p>I am currently creating a log-in system where, on top of the e-mail verification system that Firebase provides, there is another layer of authentication that I manually have to do myself. Thus, to achieve this, I introduced Firebase Realtime Database into my project. Here is a snippet of the JSON file in the database.</p>
  
  <pre><code>{
   "users" : {
    "abfkbnqeiurbnafjbnaojn" : {
     "app_authorized" : 1,
     "email" : "example51245@gmail.com",
     "full_name" : "Test Sample",
     "user_id" : "abfkbnqeiurbnafjbnaojn"
    }
   }
  }
  </code></pre>
  
  <p>As you can see from the JSON file, the app_authorized key-value pair will govern whether the user can sign-in or not (0 means the user is not eligible while 1 means the user is eligible to sign-in). I am using the user's UID from Firebase's sign-in with e-mail and password system for the parent for all key-value pairs. I am also aware that the value type for app_authorized is long.</p>
  
  <p>Here is the code that I used in my SignInActivity.</p>
  
  <pre><code>long isAppAuthorized;
  
  //some codes here
  
  private void init() {
  
          btnSignIn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Log.d(TAG, "onClick: attempting to log in");
  
                  String email = emailEditText.getText().toString();
                  String password = passwordEditText.getText().toString();
  
                  //validates respective EditTexts
                  if (TextUtils.isEmpty(email)) {
  
                      emailEditText.setError("Please fill in your e-mail address!");
  
                  }
                  else if (TextUtils.isEmpty(password)) {
  
                      passwordEditText.setError("Please fill in your password!");
  
                  } else {
  
                      progressDialog.show();
  
                      mAuth.signInWithEmailAndPassword(email, password)
                              .addOnCompleteListener(SignInActivity.this, new OnCompleteListener&lt;AuthResult&gt;() {
                                  @Override
                                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                                      Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
  
                                      FirebaseUser user = mAuth.getCurrentUser();
                                      firebaseDatabase = FirebaseDatabase.getInstance();
  
                                      userID = user.getUid();
  
                                      final DatabaseReference myRef = firebaseDatabase.getReference("users/" + userID + "/app_authorized");
  
                                      myRef.addValueEventListener(new ValueEventListener() {
                                          @Override
                                          public void onDataChange(DataSnapshot dataSnapshot) {
                                              //gets value of isAppAuthorized
                                              isAppAuthorized = dataSnapshot.getValue(long.class);
                                          }
  
                                          @Override
                                          public void onCancelled(DatabaseError databaseError) {
  
                                          }
                                      });
  
                                      // If sign in fails, display a message to the user. If sign in succeeds
                                      // the auth state listener will be notified and logic to handle the
                                      // signed in user can be handled in the listener.
                                      if (!task.isSuccessful()) {
  
                                          Log.w(TAG, "signInWithEmail:failed", task.getException());
                                          Toast.makeText(SignInActivity.this, R.string.auth_failed,
                                                  Toast.LENGTH_SHORT).show();
                                          progressDialog.dismiss();
  
                                      } else {
  
                                          try {
                                              //this is the part where I check for both isEmailVerified and isAppAuthorized
                                              if(user.isEmailVerified() &amp;&amp; isAppAuthorized == 1) {
  
                                                  Log.d(TAG, "onComplete: success. e-mail is verified " + user.isEmailVerified() + " userIsAuthorized: " + isAppAuthorized);
                                                  Intent intent = new Intent(SignInActivity.this, HomeActivity.class);
                                                  startActivity(intent);
  
                                              } else {
  
                                                  Log.d(TAG, "onComplete: failed: isEmailVerified: " + user.isEmailVerified() + " userIsAuthorized: " + isAppAuthorized);
  
                                                  progressDialog.dismiss();
                                                  mAuth.signOut();
                                                  Intent intent = new Intent(SignInActivity.this, MainActivity.class);
                                                  startActivity(intent);
  
                                              }
  
                                          } catch(NullPointerException e) {
  
                                              Log.e(TAG, "onComplete: NullPointerException: " + e.getMessage());
  
                                          }
                                      }
  
                                      // ...
                                  }
                              });
                  }
              }
          });
  
      }
  </code></pre>
  
  <p>The problem that I encountered is that the isAppAuthorized long always returns 0 regardless of what value I put into the database, thus, rendering my second layer of authorization useless. </p>
  
  <p>I hope that someone is able to help me with this as I have tried many things and am still unable to understand the source of the problem.</p>