Webservices with Retained Fragments
<p>I have a Fragment that is used to retrieve some data from my CMS with the help of the Volley lib. I am using RecyclerViews to do that. It works. However when I am rotating the screen,the webservice is run again. How can I stop that? I tried to use **setRetainInstance(true); but at no vail. From what I have read,this method bypasses the onDestroy() fragment's method,and hence the onCreate() fragment's method is not called when you rotate the screen. If I am wrong with that please correct me. Here is my code.</p>

<p><strong>FeaturesActivity</strong></p>

<pre><code>public class FeaturesActivity extends AppCompatActivity {
private static final String FEATURES_FRAGMENT = "Features_fragment";
FeaturesFragment ff;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_features);

    FragmentManager fragmentManager = getSupportFragmentManager();
    ff = (FeaturesFragment) fragmentManager.findFragmentByTag(FEATURES_FRAGMENT);

    if(ff == null) {
        ff = new FeaturesFragment();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(android.R.id.content, ff);
        fragmentTransaction.commit();
    }
  }
}
</code></pre>

<p>And the actual fragment itself.</p>

<pre><code>public class FeaturesFragment extends Fragment {

public static final String TAG = "ManuApp";
private static final String IMAGE_URL = "http://xxx/xxx/features_images/" ;
private List&lt;FeaturesObject&gt; listItemsList;

private RecyclerView mRecyclerView;
private FeaturesAdapter adapter;

public FeaturesFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    Log.v("retained","oncreate called");
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {


    View v = inflater.inflate(R.layout.fragment_features, container, false);
    // Inflate the layout for this fragment
    listItemsList = new ArrayList&lt;&gt;();
    mRecyclerView = (RecyclerView)v.findViewById(R.id.features_recycler_view);
    //mRecyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity()).color(Color.BLACK).build());

    final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(linearLayoutManager);


    return v;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    updateFeaturesList();
}

public void updateFeaturesList() {




    //declare the adapter and attach it to the recyclerview
    adapter = new FeaturesAdapter(getActivity(), listItemsList);
    mRecyclerView.setAdapter(adapter);

    // Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(getActivity());



    // Request a string response from the provided URL.
    JsonArrayRequest jsObjRequest = new JsonArrayRequest(Request.Method.GET, Config.URL_FEATURES, new Response.Listener&lt;JSONArray&gt;() {

        @Override
        public void onResponse(JSONArray response) {

            Log.d(TAG, response.toString());
            //hidePD();

            // Parse json data.
            // Declare the json objects that we need and then for loop through the children array.
            // Do the json parse in a try catch block to catch the exceptions
            try {



                for (int i = 0; i &lt; response.length(); i++) {

                    JSONObject post = response.getJSONObject(i);
                    FeaturesObject item = new FeaturesObject();
                    item.setTitle(post.getString("title"));
                    item.setImage(IMAGE_URL + post.getString("features_image"));
                    item.setArticle(post.getString("article"));



                    listItemsList.add(item);

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            // Update list by notifying the adapter of changes
            adapter.notifyDataSetChanged();
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            //hidePD();
        }
    });

    queue.add(jsObjRequest);

  }
 }
</code></pre>

<p>I logged out a message inside the onCreate(...),but it is called even if I rotate the screen. How can I fix that? </p>

<p>Thanks.</p>