title: list of images not showing up after search button is pressed
body: <p>I am getting image urls using google image search apis. i use okhttp to connect to the url. this is done in my activity's oncreate method. in the oncreate() method of fragment i get all the image urls and store them in mSmallIMagesUrl, in the oncreateView() i try to display the images using a customized adapter. but when i run my app, hit the search button, it shows a blank page, when i go back and click the search button(there is always text in the search box) it shows images of the the previous search text. i dont know why it this,below is my code, please let me know what i am missing. thanks </p>
  
  <pre><code>package com.paveynganpi.allsearch;
  
  import android.content.Context;
  import android.content.Intent;
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  import android.support.annotation.Nullable;
  import android.support.v7.app.ActionBarActivity;
  import android.support.v7.app.ActionBar;
  import android.support.v4.app.Fragment;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.os.Build;
  import android.widget.AbsListView;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.GridView;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.squareup.okhttp.Call;
  import com.squareup.okhttp.Callback;
  import com.squareup.okhttp.OkHttpClient;
  import com.squareup.okhttp.Request;
  import com.squareup.okhttp.Response;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  import org.w3c.dom.Text;
  
  import java.io.IOException;
  import java.util.ArrayList;
  
  
  public class ImageGrid extends ActionBarActivity {
  
  private static final String TAG = ImageGrid.class.getSimpleName();
  
  protected int start = 0;//variable to change pages from google Api
  
  //contains extra images urls to supply to ... when need
  protected  static ArrayList&lt;ArrayList&lt;String&gt;&gt; mBigImagesUrls = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
  //contains image urls to inject into gridview
  protected static  ArrayList&lt;String&gt; mSmalImagesUrls = new ArrayList&lt;&gt;();
  
  protected static String mEditedString;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_image_grid);
      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.container, new PlaceholderFragment())
                  .commit();
      }
  
  
     for (int start = 0; start &lt; 2; start++) {
  
  
          if (isNetworkAvailable()) {
  
              //using okHttp library to connect to imagesUrl and retrieve JSON Data
              OkHttpClient client = new OkHttpClient();
              Request request = new Request.Builder()
                      .url(getImagePage(start)).
                              build();
  
              Call call = client.newCall(request);
  
              //runs the below code asynchronously
              call.enqueue(new Callback() {
                  @Override
                  public void onFailure(Request request, IOException e) {
                      Log.v(TAG, "error from request");
  
                  }
  
                  @Override
                  public void onResponse(Response response) throws IOException {
  
                      try {
                          String jsonData = response.body().string();
                          //Log.v(TAG, jsonData);
  
                          if (!response.isSuccessful()) {
                              alertUserAboutError();
                          } else {
  
                             // mSmalImagesUrls = getCurrentDetails(jsonData);
                              mBigImagesUrls.add(getCurrentDetails(jsonData));
                              Log.d(TAG, mBigImagesUrls.size() + " big size");
                              Log.d(TAG, mSmalImagesUrls.size() + " small size");
  
                          }
                      } catch (IOException | JSONException e) {
                          Log.e(TAG, "Exception caught :", e);
                      }
                  }
              });
          } else {
              Toast.makeText(this, "Network is unavailable", Toast.LENGTH_LONG).show();
          }
      }
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_image_grid, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  
  private String getImagePage(int start) {
      return "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&amp;q="
              + mEditedString + "&amp;rsz=8&amp;start=" + start;
  }
  
  //get data
  private ArrayList&lt;String&gt; getCurrentDetails(String jsonData) throws JSONException {
  
      JSONObject jsonObject = new JSONObject(jsonData);
      JSONObject responseData = jsonObject.getJSONObject("responseData");
  
      ArrayList&lt;String&gt; localList = new ArrayList&lt;String&gt;();
  
      JSONArray results = responseData.getJSONArray("results");
  
  
      for (int i = 0; i &lt; results.length(); i++) {
  
          localList.add(results.getJSONObject(i).getString("url"));
  
      }
  
      return localList;
  
  }
  
  //An AlertDialog to display to user when an error occurs
  private void alertUserAboutError() {
  
      AlertDialogFragment dialog = new AlertDialogFragment();
      dialog.show(getFragmentManager(), "error_dialog");
  
  
  }
  
  //checks if user is connected to a network
  private boolean isNetworkAvailable() {
  
      ConnectivityManager cm =
              (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  
      NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
      boolean isAvailable = false;
  
      if (activeNetwork != null &amp;&amp; activeNetwork.isConnectedOrConnecting()) {
          isAvailable = true;
      }
      return isAvailable;
  
  
  }
  
  @Override
  public void onBackPressed() {
      super.onBackPressed();
  
      Log.d(TAG,"back was pressed");
      mBigImagesUrls.clear();
      mSmalImagesUrls.clear();
  
  
  }
  
  /**
   * A placeholder fragment containing a simple view.
   */
  public static class PlaceholderFragment extends Fragment {
  
      protected GridView mGridView;//reference to gridview in fragment_image_grid.xml
  </code></pre>
  
  <p>static String mEditedString;</p>
  
  <pre><code>    @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          Log.d(TAG, mBigImagesUrls.size() + " final big size");
          Log.d(TAG, mSmalImagesUrls.size() + "final small size");
  
  
          for(int i =0;i&lt;mBigImagesUrls.size();i++){
  
              for(int j =0;j&lt;8;j++){
  
                  mSmalImagesUrls.add(mBigImagesUrls.get(i).get(j));
  
              }
  
          }
  
      }
  
      public PlaceholderFragment() {
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          final View rootView = inflater.inflate(R.layout.fragment_image_grid, container, false);
  
          final ArrayList&lt;String&gt; testList = new ArrayList&lt;String&gt;();
  
          //gets the edited string from MainActivity
          Bundle args = getActivity().getIntent().getExtras();
          mEditedString = args.getString("space");
  
          mGridView = (GridView)rootView.findViewById(R.id.imagesGrid);//reference to gridview
          ImagesGridAdapter adapter = new ImagesGridAdapter(getActivity(), mSmalImagesUrls);
          mGridView.setAdapter(adapter);
  
  
          return rootView;
      }
  
  
  
  }
  </code></pre>
  
  <p>}</p>