title: Save String from Override onDataChange to see outside in Android Firebase
body: <p>I've a String variable from a database. I've an access in @Override onDataChange method.</p>
  
  <p>But I'd like to see that value of this string in outside of this @Override method. At now, I cannot see, because value of this string from database is available only in @Override method.</p>
  
  <pre><code>    firebase.addValueEventListener(new ValueEventListener() {
                  @Override
                  public void onDataChange(DataSnapshot dataSnapshot) {
  
                      CarClass carClass = dataSnapshot.getValue(CarClass.class);
  
                      string1 = carClass.getCarName();
                      // value of "string1" is = "name"
  
                  }
  
                  @Override
                  public void onCancelled(FirebaseError firebaseError) {
  
                  }
              });
  // here value of "string1" is empty.
  </code></pre>
  
  <p>Does someone could help me to resolve this problem?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>I found solution myself:</strong></p>
  
  <p>To have an access of value of "string1" from "onDataChange method" I used SharedPreferences. I put this "string1" to SharedPreferences in @Override method, and I can get this value of "string1" outside of this method using SharedPreferences.</p>
  
  <p>I show my explanation below:</p>
  
  <pre><code>     public static final String Car_Name = "Name_PREFS";
       public static final String Car_Key = "String_PREFS";
       SharedPreferences sharedPreferences;
  
        firebase.addValueEventListener(new ValueEventListener() {
                          @Override
                          public void onDataChange(DataSnapshot dataSnapshot) {
  
                              CarClass carClass = dataSnapshot.getValue(CarClass.class);
  
                              string1 = carClass.getCarName();
  
  
      sharedPreferences = getApplicationContext().getSharedPreferences(Car_Name, Context.MODE_PRIVATE);
         SharedPreferences.Editor editor = sharedPreferences.edit();
                      editor.putString(Car_Key, string1);
                      editor.apply();
  
  
                          }
  
                          @Override
                          public void onCancelled(FirebaseError firebaseError) {
  
                          }
                      });
  
  
      sharedPreferences = getApplicationContext().getSharedPreferences(Car_Name, MODE_PRIVATE);
              string1 = sharedPreferences.getString(Car_Key, null);
              // here value of "string1" exists outside of "onDataChange" method.
  // string1 = "name"
      }
  </code></pre>