title: How to set global var from onDataChange function
body: <p>I'm using firebase in my project and i'm trying to figure out how to fix the next issue for few hours already without success,
  I have the next code:</p>
  
  <pre><code>// gameIDperm is set as 0 as default
      public void GenerateID(){
              ref2.addListenerForSingleValueEvent(new ValueEventListener() {
                  @Override
                  public void onDataChange(DataSnapshot snapshot) {
                      if(snapshot.hasChild(gameIDperm))
                      {
                          gameIDperm = Integer.toString(Integer.parseInt(gameIDperm)+1); 
                          Log.d("ID XXXX" , gameIDperm); // Here it says the right number
                      }
                  }
  
                  @Override
                  public void onCancelled(DatabaseError databaseError) {
  
                  }
              });
              Log.d("ID YYYYYYYY" , gameIDperm); // Here it says gameIDperm is 0 again
  
          }
  </code></pre>
  
  <p>How can i make the variable being saved in the current function and not being reset again to default?</p>
  
  <p>Hope you can help!</p>