Passing Serializable Objects using AsyncTask
<p>So I am parsing a <code>JSONObject</code> using the <code>JSON Parser</code>, and put that data into several objects using an <code>AsyncTask</code>. My question is: How would I pass all these objects? They are all <code>Serializable</code> and I've read that you can just create an <code>Intent</code> and put the objects into the <code>Intent</code> using the <code>putExtras</code> method; however, when I do this, I get an error. </p>

<p>Also, to create all the objects, I call the constructors of each of the different objects using constructors, in the original constructor. So I can call one constructor, and that constructor call the other constructors, using methods within the first constructor. I know it might sound a little confusing, but ultimately the parser creates 8 different objects that I want to pass to the next activity.</p>

<p>I'm open to any suggestions on how to do this.</p>

<p>EDIT: I don't want to use<code>Parcelable</code> it is far to complex for what I am trying to do and I am not worrying about speed as my file is small.</p>

<pre><code>@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);

        checkWifiConnection(menuUrl);

    }




    class LoadJSON extends AsyncTask&lt;String, Void, Restaurant&gt;{

        @Override
        protected Restaurant doInBackground(String... params) {
            JSONObject jo=null;
            Restaurant rest = null;

            try {

                Log.i(TAG, "Running background thread"); 
                URL mURL = new URL(menuUrl);
                Log.i(TAG, mURL + ": menuUrl"); 
                URLConnection uc = mURL.openConnection();


                JsonParser parser = new JsonParser(); 

                try {
                    jo = parser.getJson(getApplicationContext(), uc);
                    rest = new Restaurant(jo); &lt;&lt;-- Start the parsing using this constructor, which calls the other objects constructors
                } catch (IOException e) {

                    e.printStackTrace();
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }



            } catch (MalformedURLException e) {

                e.printStackTrace();
            } catch (IOException e) {

                e.printStackTrace();
            } 
            return rest;
        }

        @Override
        protected void onPostExecute(Restaurant rest){

            ImageButton ib = (ImageButton)findViewById(R.id.continuebutton); 
            ib.setVisibility(View.VISIBLE); 
            ib.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    Intent homeIntent = new Intent(MainActivity.this, HomeActivity.class); 
                    homeIntent.putExtra("Restaurant", rest); //&lt;&lt; get an error here
                    startActivity(homeIntent); 


                }
            }); 

        }
</code></pre>

<p>Here is the <code>Restaurant</code> class:</p>

<pre><code>package com.uie.menu.app;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class Restaurant implements Serializable {

    private final static String TAG = Restaurant.class.getSimpleName();

    String name;
    String category;
    String created_at;
    String updated_at;
    private List&lt;Menu&gt; menuList;
    private List&lt;SideDishes&gt; sideDishes;
    private List&lt;Drinks&gt; drinks; 
    private List&lt;Ingredients&gt; ingredients; 
    private List&lt;DrinkCategories&gt; drinkCategories; 

    private Restaurant() {
        menuList = new ArrayList&lt;Menu&gt;();
        sideDishes = new ArrayList&lt;SideDishes&gt;();
        drinks = new ArrayList&lt;Drinks&gt;();
        ingredients = new ArrayList&lt;Ingredients&gt;(); 
        drinkCategories = new ArrayList&lt;DrinkCategories&gt;(); 
    }

    public Restaurant(JSONObject jo) throws JSONException {

        this();

        if (jo != null) {

            this.name = jo.optString("name");
            Log.i(TAG, name + " : Restaurant 'name'");
            this.category = jo.optString("category");
            Log.i(TAG, category + " : Restaurant category");
            this.created_at = jo.optString("created_at");
            Log.i(TAG, created_at + " : Restaurant 'created at'");
            this.updated_at = jo.optString("updated_at");
            Log.i(TAG, updated_at + " : Restaurant 'updated_at'");

            addMenus(jo);
            addMenuSides(jo); 
            addMenuDrinks(jo); 
            addMenuIngredients(jo); 
            addDrinkCategories(jo); 

        }

    }

    private void addMenus(JSONObject jo) throws JSONException {
        JSONArray menus = jo.optJSONArray("menus");

        if (menus != null) {
            for (int ii = 0; menus != null &amp;&amp; ii &lt; menus.length(); ii++) {
                JSONObject menu = menus.optJSONObject(ii);
                Log.d(TAG,  "==Adding Restaurant Menu==");
                addMenu(new Menu(menu));
            }
            Log.d(TAG, "==Done adding Restaurant Menu==");
        }
    }

    private void addMenu(Menu menu) {
        menuList.add(menu);
    }

    private void addMenuSides(JSONObject jo) throws JSONException{
        JSONArray sides = jo.optJSONArray("side_dishes");

        if (sides != null) {
            for (int ii = 0; sides != null &amp;&amp; ii &lt; sides.length(); ii++) {
                JSONObject side = sides.optJSONObject(ii);
                Log.d(TAG,  "==Adding Restaurant Side Dish==");
                addSide(new SideDishes(side));
            }
            Log.d(TAG, "==Done adding Restaurant Side Dishes==");
        }
    }

    private void addSide(SideDishes side){
        sideDishes.add(side); 
    }

    private void addMenuDrinks(JSONObject jo) throws JSONException{
        JSONArray drinks = jo.optJSONArray("drinks");

        if (drinks != null) {
            for (int ii = 0; drinks != null &amp;&amp; ii &lt; drinks.length(); ii++) {
                JSONObject drink = drinks.optJSONObject(ii);
                Log.d(TAG,  "==Adding Restaurant Drinks==");
                addDrink(new Drinks(drink));
            }
            Log.d(TAG, "==Done adding Restaurant Drinks==");
        }
    }

    private void addDrink(Drinks drink){
        drinks.add(drink); 
    }

    private void addMenuIngredients(JSONObject jo){
        JSONArray ingredients = jo.optJSONArray("ingredients");

        if (ingredients != null) {
            Log.d(TAG,  "==Adding Restaurant Ingredient==");
            for (int ii = 0; ingredients != null &amp;&amp; ii &lt; ingredients.length(); ii++) {
                JSONObject ingredient = ingredients.optJSONObject(ii);

                addIngredient(new Ingredients(ingredient));
            }
            Log.d(TAG, "==Done adding Restaurant Ingredients==");
        }
    }

    private void addIngredient(Ingredients ingredient){
        ingredients.add(ingredient); 
    }

    private void addDrinkCategories(JSONObject jo) throws JSONException{
        JSONArray drinkCategories = jo.optJSONArray("drink_categories");

        if (drinkCategories != null) {
            Log.d(TAG,  "==Adding Restaurant Drink Categories==");
            for (int ii = 0; drinkCategories != null &amp;&amp; ii &lt; drinkCategories.length(); ii++) {
                JSONObject drinkCategory = drinkCategories.optJSONObject(ii);

                addCategory(new DrinkCategories(drinkCategory));
            }
            Log.d(TAG, "==Done adding Restaurant Drink Categories==");
        }
    }

    private void addCategory(DrinkCategories drinkCategory){
        drinkCategories.add(drinkCategory); 
    }
}
</code></pre>

<p>There error that I get is: <code>Cannot refer to a non-final variable rest inside an inner class defined in a different method</code></p>
