Insider's Guide To Udacity Android Developer Nanodegree Part 3 - Making the Baking App
Insider's Guide To Udacity Android Developer Nanodegree Part 3 - Making the Baking App
Written by Nikos Vaggalis   
Monday, 03 July 2017
Article Index
Insider's Guide To Udacity Android Developer Nanodegree Part 3 - Making the Baking App
Step 1 - Fragments
Fragments In Action
Step 2 - Libraries & Networking
POJO To Parcelables
Step 3 - Adding Exoplayer
Step 4 - Widgets
Step 5 - The Widget Provider
Step 6 - UI Testing
Step 7 - Testing Intents

The next and last step in this chain of conversions is do the same from POJO to Parcelable.Well there's a converter for that too! Head over to, paste each of the Recipe, Ingredient and Step Java classes into its webform and viola, we got our Parcelables back!

As a sample of the generated files, let's take a look at what class was converted to:

Ingredient POJO turned Parcelable


import android.os.Parcel;
import android.os.Parcelable;

public class Ingredient implements Parcelable {

    private Double quantity;
    private String measure;
    private String ingredient;

    public Double getQuantity() {
        return quantity;

    public void setQuantity(Double quantity) {
        this.quantity = quantity;

    public String getMeasure() {
        return measure;

    public void setMeasure(String measure) {
        this.measure = measure;

    public String getIngredient() {
        return ingredient;

    public void setIngredient(String ingredient) {
        this.ingredient = ingredient;

    protected Ingredient(Parcel in) {
        quantity = in.readByte() == 0x00 ?
                           null : in.readDouble();
        measure = in.readString();
        ingredient = in.readString();

    public int describeContents() {
        return 0;

    public void writeToParcel(
                      Parcel dest, int flags) {

        if (quantity == null) {
            dest.writeByte((byte) (0x00));
        } else {
            dest.writeByte((byte) (0x01));

    public static final Parcelable.Creator<Ingredient>
       CREATOR = new Parcelable.Creator<Ingredient>() {
        public Ingredient createFromParcel(Parcel in) {
            return new Ingredient(in);

        public Ingredient[] newArray(int size) {
            return new Ingredient[size];

I didn't wrap those objects into Parcelables for fun. I did it so that a ParcelableArrayList of Recipe super objects can cross Activities and Fragment boundaries, initially from RecipeActivity


 recipe.enqueue(new Callback<ArrayList<Recipe>>() {
            public void onResponse(Call<ArrayList<Recipe>> call,
                                 Response<ArrayList<Recipe>> response) {
                ArrayList<Recipe> recipes = response.body();

                Bundle recipesBundle = new Bundle();
                                                        ALL_RECIPES, recipes);


to RecipeDetailActivity and RecipeDetailFragment so that I can extract both the list of Ingredients and Steps to fill their associated views:


        if(savedInstanceState != null) {
            recipe = savedInstanceState
        else {
            recipe =getArguments()

        List<Ingredient> ingredients = recipe.get(0).getIngredients();

        View rootView = inflater.inflate(
              R.layout.recipe_detail_fragment_body_part, container, false);
        textView = (TextView)rootView.findViewById(

        ArrayList<String> recipeIngredientsForWidgets=
                                                                       new ArrayList<>();

        ingredients.forEach((a) ->
                textView.append("\u2022 "+ a.getIngredient()+"\n");
                textView.append("\t\t\t Quantity:"
                textView.append("\t\t\t Measure: "

                        "Quantity: "+a.getQuantity().toString()+"\n"+
                        "Measure: "+a.getMeasure()+"\n");

        LinearLayoutManager mLayoutManager=
                                   new LinearLayoutManager(getContext());

        RecipeDetailAdapter mRecipeDetailAdapter=
            new RecipeDetailAdapter((RecipeDetailActivity)getActivity());

Two extra notes on the lambda expression used. The Jack compiler, ?which is now deprecated in the latest version of Android Studio, is still necessary for enabling for Java 8 features such as lambdas, but this also has the side effect of disabling the Android Studio's 'instant run' feature, therefore a full project re-compilation is necessary every time something has changed. This increases the time spent on the building phase of the project.

Initially I aimed for:

  Integer count=new Integer();
        ingredients.forEach((a) ->
                         +" "+a.getIngredient()+"\n");
                mTextView.append("\t\t Quantiy: "
                mTextView.append("\t\t Measure: "

which would print sequence numbers in front of each ingredient. But the compiler complained that 'count' should be final therefore it cannot be assigned within the lambda's scope, in effect turning off closures. As it turns out, Java can't close over variables so in reality it has got limited closures. Scrapping that, I went with just printing a dot in front of each ingredient with "\u2022 "

Last Updated ( Tuesday, 04 July 2017 )

RSS feed of all content
I Programmer - full contents
Copyright © 2017 All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.