title: save arraylist in shared preference
body: <p>I am storing values in <code>ArrayList</code> and pass it to using bundle to next <code>Fragment</code>, and there I set values to my <code>TextView</code>, till here it works fine, now when go to another page and proceed to app and come back again to that <code>Fragment</code>, my all data goes, so I am trying to store it in preferences but preference don't allow to access <code>ArrayList</code>, following is my code</p>
  
  <pre><code> public class Add_to_cart extends Fragment {
  
      private Button continue_shopping;
      private Button checkout;
      ListView list;
      private TextView _decrease,mBTIncrement,_value;
      private CustomListAdapter adapter;
      private ArrayList&lt;String&gt; alst;
      private ArrayList&lt;String&gt; alstimg;
      private ArrayList&lt;String&gt; alstprc;
      private String bname;
      private ArrayList&lt;String&gt; alsttitle;
      private ArrayList&lt;String&gt; alsttype;
  
      public static ArrayList&lt;String&gt; static_Alst;
      public Add_to_cart(){}
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
  
          final View rootView = inflater.inflate(R.layout.list_view_addtocart, container, false);
  
          alst=new ArrayList&lt;String&gt;();
          alstimg=new ArrayList&lt;String&gt;();
          Bundle bundle = this.getArguments();
          alst = bundle.getStringArrayList("prducts_id");
          alsttype = bundle.getStringArrayList("prducts_type");
          alstimg=bundle.getStringArrayList("prducts_imgs");
          alsttitle=bundle.getStringArrayList("prducts_title");
  
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy);
  
          System.out.println("TEst--" + alst);
  
         // Toast.makeText(getActivity(),"Testing"+alstimg,Toast.LENGTH_LONG).show();
          list=(ListView)rootView.findViewById(R.id.list_addtocart);
  
          adapter = new CustomListAdapter(getActivity(),alst,alstimg,alsttitle,alsttype);
  
          list.setAdapter(adapter);
          adapter.notifyDataSetChanged();
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,int position, long id) {
                  // TODO Auto-generated method stub
              }
          });
          return rootView;
      }
  
      public class CustomListAdapter extends BaseAdapter {
  
          private Context context;
          private ArrayList&lt;String&gt; listData;
          private ArrayList&lt;String&gt; listDataimg;
          private ArrayList&lt;String&gt; listDatatitle;
          private ArrayList&lt;String&gt; listDatatype;
          private AQuery aQuery;
          String dollars="\u0024";
  
          public CustomListAdapter(Context context,ArrayList&lt;String&gt; listData,ArrayList&lt;String&gt; listDataimg,ArrayList&lt;String&gt; listDatatitle,ArrayList&lt;String&gt; listDatatype) {
              this.context = context;
              this.listData=listData;
              this.listDataimg=listDataimg;
              this.listDatatitle=listDatatitle;
              this.listDatatype=listDatatype;
             aQuery = new AQuery(this.context);
          }
  
          public void save_User_To_Shared_Prefs(Context context) {
              SharedPreferences appSharedPrefs = PreferenceManager
                      .getDefaultSharedPreferences(context.getApplicationContext());
              SharedPreferences.Editor prefsEditor = appSharedPrefs.edit();
              Gson gson = new Gson();
              String json = gson.toJson(listData);
              Add_to_cart.static_Alst=listData;
              prefsEditor.putString("user", json);
              prefsEditor.commit();
          }
  
          @Override
          public int getCount() {
              return listData.size();
          }
  
          @Override
          public Object getItem(int position) {
              return listData.get(position);
          }
  
          @Override
          public long getItemId(int position) {
              return position;
          }
  
          @Override
          public View getView(final int position, View convertView, ViewGroup parent) {
              ViewHolder holder;
              if (convertView == null) {
                  holder = new ViewHolder();
                  convertView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_addtocart, null);
                  holder.propic = (ImageView) convertView.findViewById(R.id.img_addtocart);
                  holder.txtproname = (TextView) convertView.findViewById(R.id.proname_addtocart);
                  holder.txtprofilecast = (TextView) convertView.findViewById(R.id.proprice_addtocart);
                  holder.txtsize = (TextView) convertView.findViewById(R.id.txt_size);
                  _decrease = (TextView) convertView.findViewById(R.id.minuss_addtocart);
                  mBTIncrement = (TextView) convertView.findViewById(R.id.plus_addtocart);
                  _value = (EditText)convertView.findViewById(R.id.edt_procount_addtocart);
  
                  convertView.setTag(holder);
              }else{
                  holder = (ViewHolder) convertView.getTag();
              }
  
              mBTIncrement.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      increment();
                  }
              });
  
              _decrease.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
  
                      decrement();
                  }
              });
  
              holder.txtprofilecast.setText(dollars+listData.get(position));
              holder.txtproname.setText(listDatatitle.get(position));
              holder.txtsize.setText(listDatatype.get(position));
              System.out.println("Image ka array " + listDataimg.get(position));
  
              //Picasso.with(mContext).load(mThumbIds[position]).centerCrop().into(imageView);
              // Picasso.with(context).load(listDataimg.get(position)).into(holder.propic);
              aQuery.id(holder.propic).image(listDataimg.get(position), true, true, 0, R.drawable.ic_launcher);
  
              return convertView;
          }
  
          class ViewHolder{
              ImageView propic;
              TextView txtproname;
              TextView txtprofilecast;
              TextView txtsize;
          }
      }
  }
  </code></pre>