Fragment crashes with Parcel: unable to marshal value error when onPause method is called
If you already get data you need, then just remove data from bundle.
// get your dataBundle bundle = getArguments();JSONObject myData = (JSONObject) bundle.getSerializable("myData");// remove itgetArguments().remove("myData");
Well I managed to figure a way out of this, it may not be the most standard of way of doing things but it actually solved my problem and might help others to some extent.
What I did was instead of converting the JSONArray that was received from the API into a JSON arraylist and then sending it to the fragment, I converted the JSON array to string and sent it along with the bundle.
ft = fm.beginTransaction(); if(currentFragment !=null){ ft.hide(currentFragment); } if(doingFragment !=null){ ft.show(doingFragment); }else{ if(mActList.size()>0){ Bundle bundle = new Bundle(); bundle.putString("array", jArrayWhat.toString()); doingFragment = new DoingFragment(); doingFragment.setArguments(bundle); ft.add(R.id.newpost_container,doingFragment, "doingFragment"); } } ft.commit();
In the fragment I received the bundle and converted the string into JSONArray.
jsonActList = new JSONArray(getArguments().getString("array"));
Then I iterated through the JSONArray and converted it into a JSONObject ArrayList. And in order to keep the changes made to the my list after the fragment has been in use, I converted the ArrayList back into a JSONArray and saved it.
@Overridepublic void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); JSONArray jArray = new JSONArray(Arrays.asList(actList)); outState.putString("jsonArray", jArray.toString());}
Now that the state was saved it could easily be restored in the onCreateView method as follows
if ((savedInstanceState != null) && (savedInstanceState.getSerializable("jsonArray") != null)) { jsonActList = new JSONArray(savedInstanceState.getString("jsonArray")); positionList = (ArrayList<String>) savedInstanceState.getSerializable("positionList"); }
This way I wouldn't have to deal with the issue of making my JSONObjects Serializable or Parcelable