title: passing Array from Api to to another activity using SharedPreferences and adding to already saved array
body: <p><strong>INTRO:</strong>
  I am trying to pass an array with sub arrays into another activity using sharedpreferences.</p>
  
  <p><strong>WHAT I WANT TO ACHIEVE</strong>: 
  I have an array of data gotten from an api of which I display as a list on a particular activity. 
  This is fine as it works. </p>
  
  <p>But I want that on item click, it saves the item data and loads in on another activity. Then on the new activity, I can add new data to that already saved information before closing the activity which then saves the data back to the database on the server.</p>
  
  <p><strong>REASON:</strong>
  I am doing it this way because of slow network connection and smooth page loading. I am trying to use SharedPreferences to save the array on item click, load it up in another activity and then add more data to the already saved array on SharedPreferences. </p>
  
  <p><strong>CURRENT STATE:</strong>
  At the moment, I can only save and get a single variable, not an array.</p>
  
  <p>This is the array:</p>
  
  <pre><code> {  "OutputCode":1,
  "OutputMessage":"Success",
  "OutputData":[
                  {
                      "id":"1",
                      "status":"1",
                      "date_borrowed":"2018-01-16 16:34:01",
                      "date_returned":"0000-00-00 00:00:00",
                      "staff_id":"1",
                      "student_id": "1",
                      "log_contents":[{   "id":"8",
                                          "log_id":"1",
                                          "book_id":"1",
                                          "quantity":"3",
                                          "book_info":{   "id":"1",
                                                          "name":"Algebra",
                                                          "author":"John Smith",
                                                          "ISBN":"987-554-3243"}},
                                      {   "id": "5",
                                          "log_id": "1",
                                          "book_id": "1",
                                          "quantity": "2",
                                          "book_info": {  "id": "1",
                                                          "name": "C++",
                                                          "author": "Jane Smith",
                                                          "ISBN": "987-656-3870"}}],
                      "student_details":{"id":"1",
                                      "fname":"John",
                                      "lname":"James",
                                      "username":"username",
                                      "password":"password",
                                      "date_created":"2018-01-15 19:53:41",
                                      "phone":"+15673566"}
                  },
                  {
                      "id": "2",
                      "status": "0",
                      "date_borrowed": "2018-01-13 16:34:01",
                      "date_returned": "2018-01-14 17:10:14",
                      "staff_id": "1",
                      "student_id": "1",
                      "log_contents": [],
                      "student_details": {"id": "2",
                                          "fname": "Mary",
                                          "lname": "Jane",
                                          "username": "username",
                                          "password": "password",
                                          "date_created": "2018-01-15 20:53:41",
                                          "phone": "+14768986"}
                  }]}
  </code></pre>
  
  <p>This is the code</p>
  
  <pre><code>    access.runCommand("get_all_bookings", keys, values, new AtomAccess.Callback() {
          @Override
          public void onSuccess(JSONObject output) {
              try {
                  String outputCode = output.getString("outputCode");
                  String outputMessage = output.getString("outputMessage");
  
                  updtedlist = (ListView) findViewById(R.id.lib_book_list_view);
  
                  if (outputCode.equals("1")) {
                      JSONArray outputData = output.getJSONArray("outputData");
                      for (int i = 0; i &lt; outputData.length(); i++) {
                          JSONObject obj = outputData.getJSONObject(i);
                          JSONObject stu = obj.getJSONObject("student_details");
                          Student bookBorrower = new Student(
                                  stu.getString("id"),
                                  stu.getString("fname"),
                                  stu.getString("lname"),
                                  stu.getString("username"),
                                  stu.getString("password"),
                                  stu.getString("date_created"),
                                  stu.getString("phone"));
                          JSONArray cont = obj.getJSONArray("log_content");
                          ArrayList&lt;Borrow&gt; contents = new ArrayList&lt;Borrow&gt;();
                          for (int j = 0; j &lt; cont.length(); j++) {
                              JSONObject con = cont.getJSONObject(j);
                              JSONObject buk = con.getJSONObject("book_info");
                              contents.add(new Borrow(
                                      con.getString("id"),
                                      con.getString("log_id"),
                                      con.getString("book_id"),
                                      con.getString("quantity"),
                                      new Book(buk.getString("id"),
                                              buk.getString("name"),
                                              buk.getString("author"),
                                              buk.getString("ISBN"))
                              ));
  
                          }
  
                          Log log = new Log(
                                  obj.getString("id"),
                                  obj.getString("status"),
                                  obj.getString("date_borrowed"),
                                  obj.getString("date_returned"),
                                  obj.getString("staff_id"),
                                  obj.getString("student_id"),
                                  contents,
                                  bookBorrower);
  
                          open_logs.add(log);
  
                      }
                  }
  
                  updtedlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long offset) {
  
                          Log LogItem = (Log) adapter.getItem(position);
  
                          Student student = LogItem.getbookBorrower();
                          ArrayList&lt;Borrow&gt; buro = new ArrayList&lt;Borrow&gt;();
                          ArrayList&lt;Book&gt; buk = new ArrayList&lt;Book&gt;();
                          buro = LogItem.getContents();   //Here, am trying to get array of model 'Borrow' and 'Book'
                          Log.v("buro :", ""+buro); // the result here is [com.samuel.booking.entity.Product@e8f6200, com.samuel.booking.entity.Product@aad103]
  
                          SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
                          SharedPreferences.Editor editor = settings.edit();
                          editor.putString("fang", ""+student.getFirstName()); // This return the right info
                          editor.putString("lang", ""+buro);  // This yields no result except that in the log above
                          editor.apply();
  
                          //I was able to get the variable below
                          Intent i =  new Intent(LogsActivity.this, LogInfoActivity.class);
                          // i.putExtra("KEY_log_ID", LogItem.getId());
                          // i.putExtra("KEY_Log_STATUS", LogItem.getStatus());
                          // i.putExtra("KEY_Los_Student_ID", student.getId());
                          // i.putExtra("KEY_Log_Student_FNAME", student.getFirstName())
                          startActivity(i);
  
                      }
  
                  });
  
                  adapter = new LogsAdapter(LogsActivity.this, open_Logs);
                  updtedlist.setAdapter(adapter);
                  removeLoadingOverlay();
              } catch (JSONException e) {
  
              }
          }
      });
  </code></pre>
  
  <p>I would gladly go with a better way of achieving this. I just want to avoid loading the data from Api all the time.</p>