Something I do not understand what's the matter ...
I load the data in the portions and I display the list. If you change the orientation of the screen when loading data, the exception is "IllegalArgumentException:
How to get rid of it?

And one more question: after loading another piece of data, changing the orientation of the screen, and then all the loaded data disappears and the list starts to load again, from the very beginning.


class NetWork extends AsyncTask<String, Integer, Void> { protected ProgressDialog proDialog; @Override protected void onPreExecute() { proDialog = new ProgressDialog(EngineBrowseByOnline.this); proDialog.setMessage("Loading search engines..."); proDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); proDialog.setCancelable(true); proDialog.show(); } @Override protected Void doInBackground(String... params) { rsj = new ReadStringJson(SERVER_URL + SERVER_PATH_1 + "from=" + (from+1) + "&number=" + number + SERVER_PATH_2 + GROUP); try { // здесь идет парсинг json и заполнение names, // descriptions и logoUrl parsingData(rsj.readFromServer()); } catch (IOException ex) { Log.e("IOException: ", ex.toString()); ex.printStackTrace(); } catch (JSONException ex) { Log.e("JSONException: ", ex.toString()); ex.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); adapter.addEnginesNames(names); adapter.addEnginesDescriptions(descriptions); adapter.addEnginesLogoUrl(logoUrl); adapter.notifyDataSetChanged(); proDialog.dismiss(); } } 
  • materiel tried to read? when a coup is fully activated, the old streams continue to work, new ones are started anew and many more interesting things happen :) - Gorets
  • tried to read, but did not understand how to solve the problem ... - Stas0n

2 answers 2

To begin with, it would be nice to see the code.

When you change orientation, onPause () / OnResume () is called , or o onPause () / onStop () / onResume () / onRestart () / onStart () / onResume () - this leads to a reload of all content. You can get around this by saving the intermediate data in the Bundle savedInstanceState - note also that this is the only onCreate () argument. In fact, more theory is needed, but it is better to read the original source yourself.

  • Added code. This source read, but something did not really help .. - Stas0n

This is good, read at your leisure how to work with streams and not lose connection with them.

PS

still as an option I would advise configChanges = "orientation | screenSize" in the manifest for activity. This suggests that any changes in the size of the screen or its rotation you will catch yourself, while with these changes the activity will not be recreated.

BUT:

There are magic apparatuses on which such things do not work. then the article comes to the rescue, about which I wrote above.