# Errata for Android Apprentice 4th Edition

**URL:** <https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809>\
**Category:** Android Apprentice\
**Created:** [April 27, 2021, 10:11pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809 "2021-04-27T22:11:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jellodiil](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jellodiil/32/109742_2.png) [@jellodiil](https://forums.kodeco.com/u/jellodiil)\
**Post date:** [April 27, 2021, 10:11pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/1 "2021-04-27T22:11:52Z")

</div>

Creating this topic to catch any typos and bugs in the 4th Edition of Android Apprentice.

---

<div class="post-metadata">

**Author:** ![jellodiil](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jellodiil/32/109742_2.png) [@jellodiil](https://forums.kodeco.com/u/jellodiil)\
**Post date:** [April 27, 2021, 10:12pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/2 "2021-04-27T22:12:07Z")

</div>



---

<div class="post-metadata">

**Author:** ![cpg6b](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/cpg6b/32/81494_2.png) [@cpg6b](https://forums.kodeco.com/u/cpg6b)\
**Post date:** [May 8, 2021, 1:24am UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/3 "2021-05-08T01:24:25Z")

</div>

Hello,

I wasn’t able to compile any of the sample code in 8. SharedPreferences & ViewModels, Section “Adding a Dialog” without doing additional steps such as importing various missing references:

```
import android.text.InputType
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import com.raywenderlich.listmaker.databinding.MainActivityBinding

```

Not sure if that was intended or not but thought I’d mention it.

---

<div class="post-metadata">

**Author:** ![daemonic\_daz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/daemonic_daz/32/108563_2.png) [@daemonic\_daz](https://forums.kodeco.com/u/daemonic_daz)\
**Post date:** [May 8, 2021, 7:08pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/4 "2021-05-08T19:08:11Z")

</div>

Hi cpg6b,

Thank you for letting us know about this. I downloaded the final project for chapter 8 and can compile the app with no issue.

I was wondering if you could be more specific about the issue. Was it following along with the chapter, or something else?

---

<div class="post-metadata">

**Author:** ![cpg6b](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/cpg6b/32/81494_2.png) [@cpg6b](https://forums.kodeco.com/u/cpg6b)\
**Post date:** [May 8, 2021, 8:29pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/5 "2021-05-08T20:29:54Z")

</div>

Thanks for your response @daemonic_daz. I didn’t have a chance yet to try the downloadable sample — instead I was just following along in the chapter with adding the sample code as instructed line by line from the very beginning. Sorry for not being more clear about that.

If you start the Chapter from the beginning as a fresh project and then add or replace the lines of code as instructed, I think you’ll probably find that there might be an instruction missing along the way somewhere about adding the import statements as needed for those various objects.

If you need any more information, please let me.

Thanks!

---

<div class="post-metadata">

**Author:** ![cpg6b](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/cpg6b/32/81494_2.png) [@cpg6b](https://forums.kodeco.com/u/cpg6b)\
**Post date:** [May 8, 2021, 8:32pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/6 "2021-05-08T20:32:09Z")

</div>

Sorry forgot to remind you that it’s specifically the code in the “Adding a Dialog Part”

---

<div class="post-metadata">

**Author:** ![daemonic\_daz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/daemonic_daz/32/108563_2.png) [@daemonic\_daz](https://forums.kodeco.com/u/daemonic_daz)\
**Post date:** [May 17, 2021, 8:30pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/7 "2021-05-17T20:30:21Z")

</div>

Hi @cpg6b,

Thank you for the information. I think this is something we’ll keep in mind. We do cover how to import classes in Chapter 3. Whether that’s enough is another discussion.

---

<div class="post-metadata">

**Author:** ![psb4ever](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/psb4ever/32/81494_2.png) [@psb4ever](https://forums.kodeco.com/u/psb4ever)\
**Post date:** [May 26, 2021, 6:33pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/8 "2021-05-26T18:33:57Z")

</div>

Chapter 7  
!Here, you’re telling gradle to add the viewBinding feature to your app. Next, you need to start using data binding"

start using view binding instead of data binding?

---

<div class="post-metadata">

**Author:** ![imrhk](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/imrhk/32/102075_2.png) [@imrhk](https://forums.kodeco.com/u/imrhk)\
**Post date:** [August 18, 2021, 8:42pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/9 "2021-08-18T20:42:33Z")

</div>

In chapter 4: Debugging, there is one more bug which should be fixed.

Steps to reproduce:

1. Run the final project
2. Rotate device without hitting tap button.

Expected: The timer should not run  
Actual: Timer started running even if ‘Tap me!’ button wasn’t pressed once.

PR:

```auto
override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        if (gameStarted) {
            outState.putInt(SCORE_KEY, score)
            outState.putInt(TIME_LEFT_KEY, timeLeft)
            countDownTimer.cancel()

            Log.d(TAG, "onSaveInstanceState: Saving score: $score & Time left: $timeLeft")
        }
    }

```

Explaination: score and time left should only be saved in case game has started.

---

<div class="post-metadata">

**Author:** ![sks](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sks/32/81494_2.png) [@sks](https://forums.kodeco.com/u/sks)\
**Post date:** [October 24, 2021, 5:07pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/10 "2021-10-24T17:07:27Z")

</div>

Hi, I am stuck at page 500 of the book. Cant figure out how to finish “SearchViewModel” class properly. Would it be possible for you to provide me the whole complete file so I can see where im going wrong. So far I have been able to follow along but cant get past this. I only have the paper version of the book. I think I also found a couple of typos in the book if you can call them that:

page 484:

GlobalScope.launch {  
val results = itunesRepo.searchByTerm(“Android Developer”)  
Log.i(TAG, “Results = ${results.body()}”) \<-----missing the closing bracket of {results.body()  
}

page 491:

reads as follows

app:showAsAction=“collapseActionView|ifRoom”

but I got it work the other way around:

app:showAsAction=“ifRoom|collapseActionView”

could be these are my mistakes since I am a novice and dont understand much but I thought I’d let you know in case these are typos.

Can I download the source code for this project from somewhere?

---

<div class="post-metadata">

**Author:** ![ericwastaken](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ericwastaken/32/103488_2.png) [@ericwastaken](https://forums.kodeco.com/u/ericwastaken)\
**Post date:** [October 25, 2021, 7:29pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/11 "2021-10-25T19:29:55Z")

</div>

Hi,

Yes indeed. All the source code is in the GitHub repo.

For 4th edition, all the code is here:

> **[GitHub - raywenderlich/aa-materials: The projects and the materials that...](https://github.com/raywenderlich/aa-materials/tree/editions/4.0)**
>
> editions/4.0

Thanks,

Eric.

---

<div class="post-metadata">

**Author:** ![akozin](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/akozin/32/81494_2.png) [@akozin](https://forums.kodeco.com/u/akozin)\
**Post date:** [November 24, 2021, 9:05am UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/12 "2021-11-24T09:05:28Z")

</div>

Hello!  
When we move the logic for adding a new task to the MainViewModel in the chapter 11, the following source code is used in the book:

```auto
fun addTask(task: String) {
  list.tasks.add(task)
  onTaskAdded.invoke()
}

```

I have noticed, that data is not saved to the Shared preferences when app is running on the tablet, because `onActivityResult` is not called.  
However, in the source code for the **final** project from the book the code for this function differs:

```auto
  fun addTask(task: String) {
    list.tasks.add(task)
    updateList(list)
  }

```

Here the data is saved to the Shared preferences using `updateList(list)` method and everything works as expected.

Additionally, it seems the `updateList(list:)` method in the book contains an issue:

```auto
  fun updateList(list: TaskList) {
    sharedPreferences.edit()
      .putStringSet(list.name, list.tasks.toHashSet())
      .apply()
    lists.add(list)
  }

```

`lists.add(list)` call is not needed and it is removed in the `final` project source code too.

I think the source code in the book should be updated, because it is incorrect.

---

<div class="post-metadata">

**Author:** ![ericwastaken](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ericwastaken/32/103488_2.png) [@ericwastaken](https://forums.kodeco.com/u/ericwastaken)\
**Post date:** [November 24, 2021, 8:01pm UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/13 "2021-11-24T20:01:41Z")

</div>

Thank you for pointing this out. I’ve opened an issue for the book so that this is corrected for the next edition!

---

<div class="post-metadata">

**Author:** ![mikelnord](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mikelnord/32/102075_2.png) [@mikelnord](https://forums.kodeco.com/u/mikelnord)\
**Post date:** [March 18, 2022, 1:04am UTC](https://forums.kodeco.com/t/errata-for-android-apprentice-4th-edition/138809/14 "2022-03-18T01:04:01Z")

</div>

But this has not been fixed, the entire code of the book is full of errors. It is not possible to execute the code step by step following the instructions in the book. If we compare the code on github and the code of the book, we will find big differences. I feel cheated, return the money for the subscription
