I have an android app where I'm displaying results from my RESTfull webservice in an Activity with a RecyclerView (wrapped in a SwipeRefreshLayout). In onCreate I set up the Adapter etc. and start a request with volley. When I change the orientation of my device that same request is started.
How can I prevent my app from unnecessary web requests on orientation change?
I mean all my data is already loaded so no request is necessary.
Edit: This is my try in avoiding the requests, but after change of orientation there are still requests:
private ArrayList<Item> mDataSet;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
if (mDataSet== null){
mDataSet = new ArrayList<>();
}
if (mDataSet.size() == 0) {
startRequest();
}
//...
}