Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't save instance state in android
    primarykey
    data
    text
    <p>In my app I try to save ArrayList state with putSerializable method in onSaveInstanceState. And restore it in onCreate and onRestoreInstanceState. In my app if there is no saved instance of this object it will be create from internet data. But all the time I try to test this solution ArrayList start to downloading from network. Can anyone help me?</p> <pre><code>public class Activity extends SherlockActivity { ListView listView; SlidingMenu slidingMenu; ArrayList&lt;HashMap&lt;String, String&gt;&gt; newsList = null; String url = "/////here_my_url////"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setTitle(R.string.news_vatican); listView = (ListView) findViewById(R.id.newslist); slidingMenu = new SlidingMenu(this); slidingMenu.setMode(SlidingMenu.LEFT); slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); slidingMenu.setFadeDegree(0.35f); slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); slidingMenu.setMenu(R.layout.slidingmenu); slidingMenu.setBehindOffset(150); if (savedInstanceState != null){ newsList = (ArrayList&lt;HashMap&lt;String, String&gt;&gt;) savedInstanceState.getSerializable("list"); Log.e("Activity", "RESTORING"); } else { Log.e("Activity", "PARSING NEW"); JSONParser parser = new JSONParser(this); parser.execute(url); try { newsList = parser.get(); } catch (InterruptedException e) { e.printStackTrace(); Log.e("Activity", "Failed to get newslist"); } catch (ExecutionException e) { e.printStackTrace(); Log.e("Activity", "Failed to get newslist"); } } listView.setAdapter(new NewsAdapter(getApplicationContext(), newsList)); } @Override protected void onSaveInstanceState(Bundle savedInstanceState) { savedInstanceState.putSerializable("list", newsList); super.onSaveInstanceState(savedInstanceState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); newsList = (ArrayList&lt;HashMap&lt;String, String&gt;&gt;) savedInstanceState.getSerializable("list"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload