title: How to retrieve data from firebase database in a efficient way
body: <p>I am creating an android app in which I have to compare a node and retrieve some values if node is exist and store these values in <em><code>SharedPreferences</code></em> as shown in code:</p>
  <pre><code>dbRef = FirebaseDatabase.getInstance().getReference().child(&quot;users&quot;);
  dbRef.orderByChild(&quot;email&quot;).equalTo(mAuth.getCurrentUser().getEmail()).addListenerForSingleValueEvent(new ValueEventListener() {
      @Override
      public void onDataChange(@NonNull DataSnapshot snapshot) {
          //Toast.makeText(google_sign_in.this, &quot;In sign in firebase&quot;, Toast.LENGTH_SHORT).show();
          for (DataSnapshot ds : snapshot.getChildren()) {
              SharedPreferences.Editor editor = sf.edit();
              editor.putString(&quot;phone&quot;, ds.child(&quot;phone&quot;).getValue(String.class));
              editor.putString(&quot;email&quot;, ds.child(&quot;email&quot;).getValue(String.class));
              editor.putString(&quot;fullName&quot;, ds.child(&quot;fName&quot;).getValue(String.class));
              editor.putString(&quot;lastName&quot;, ds.child(&quot;lName&quot;).getValue(String.class));
              editor.apply();
          }
      }
      @Override
      public void onCancelled(@NonNull DatabaseError error) {
      }
  });
  
  </code></pre>
  <p><strong>OnCreate method</strong></p>
  <pre><code>sf = getSharedPreferences(SHARED_PREF, MODE_PRIVATE);
  name = sf.getString(&quot;firstName&quot;, &quot;null&quot;) + &quot; &quot; + sf.getString(&quot;lastName&quot;, &quot;null&quot;);
  </code></pre>
  <p><strong>Problem</strong></p>
  <p>name is always <code>null</code> whenever activity launched for the first time.
  When the activity launch for the first time ,data retrieving process is too slow and i received null value from <code>sharedpreference</code>even I put this block of code in <code>OnStart</code> method.</p>
  <p><strong>What i want</strong></p>
  <p>I want to retrieve all data before launching of this activity so that I don't receive <code>null</code> value from <code>sharedpreferences</code>.</p>