Android Programming: The Big Nerd Ranch Guide
by Kristin Marsicano , Brian Gardner , Bill Phillips and Chris Stewart
Copyright 2019 Big Nerd Ranch, LLC.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, contact
Big Nerd Ranch, LLC.
200 Arizona Ave NE
Atlanta, GA 30307
(770) 817-6373
http://www.bignerdranch.com/
book-comments@bignerdranch.com
The 10-gallon hat logo is a trademark of Big Nerd Ranch, Inc.
Exclusive worldwide distribution of the English edition of this book by
Pearson Technology Group
800 East 96th Street
Indianapolis, IN 46240 USA
http://www.informit.com
The authors and publisher have taken care in writing and printing this book but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
ISBN-10 0135257565
ISBN-13 978-0135257562
Fourth edition, first printing, August 2019
Release E.4.1.1
Dedication
To Phil, Noah, and Sam for loving and supporting me through multiple editions of this book. |
K.M. |
To my wife, Carley, for supporting me in all that I do and reminding me of whats important along the way. |
B.G. |
To the record player on my desk. Thanks for keeping me company through all this. I promise Ill get you a new needle soon. |
B.P. |
To my dad, David, for teaching me the value of hard work. To my mom, Lisa, for pushing me to always do the right thing. |
C.S. |
Acknowledgments
With this being our fourth edition, we find ourselves used to saying this. It always needs to be said, though: Books are not created by authors alone. They are shepherded into existence by a community of collaborators, risk-takers, and other supporters, without whom the burden of comprehending and writing all this material would be overwhelming.
Brian Hardy, who, along with Bill Phillips, had the gusto to bring the very first edition of this book into the world.
Eric Maxwell, for single-handedly writing the For the More Curious section on dependency injection, for improving our coverage of notification channels, and for addressing numerous editor remarks that touched so many pages of this book.
David Greenhalgh and Josh Skeen, for lending their expertise as we Kotlinified this book and learned how to be Android developers in a Kotlin world.
Jeremy Sherman for being a surprise Android expert just when we needed him most. Thank you, Jeremy, for your detailed, thoughtful reviews and for letting us use some of your words directly in Loopers, Handlers, and HandlerThread.
Bryan Lindsey, our resident LiveData expert (and expert in so many other Android-related things). Thanks for the special attention you gave to BeatBox and PhotoGallery.
Andrew Bailey, the most intelligent rubber duck we have ever met. Thank you for offering a listening ear many times over and for helping us talk through some tough conceptual decisions. Also, thank you for adding Oreo updates to our discussion on broadcast intents.
Jamie Lee, our intern-turned-developer-writer-editor extraordinaire. Thank you for editing slides, reviewing solutions, and addressing remarks. Your attention to detail is unparalleled and greatly appreciated.
Andrew Marshall, for proactively pushing improvements to the book, for leading one of our classes in a pinch, and for jumping in and finishing up slide edits during crunch time.
Zack Simon, our fantastically talented and soft-spoken Big Nerd Ranch designer, who beautified the nifty cheat sheet attached to this book. If you enjoy that sheet, you should find Zack and tell him so yourself. But we will also thank Zack right here: Thanks, Zack!
Our editor, Elizabeth Holaday. The famous beat author William S. Burroughs sometimes wrote by cutting up his work into little pieces, throwing them in the air, and publishing the rearrangement. Without a strong editor like Liz, our confusion and simpleminded excitement may have caused us to resort to such techniques. We are thankful that she was there to impose focus, precision, and clarity on our drafts.
Ellie Volckhausen, who designed our cover.
Anna Bentley, our copyeditor and proofreader. Thank you for sanding away the remaining rough edges of this book.
Chris Loper at IntelligentEnglish.com, who designed and produced the print and eBook versions of the book. His DocBook toolchain made life much easier, too.
Thanks to Aaron Hillegass, Stacy Henry, and Emily Herman. As a practical matter, it is not possible to do this work without Big Nerd Ranch, the company Aaron founded and that Stacy (CEO) and Emily (COO) now fearlessly lead. Thank you.
Finally, thanks to our students. There is a feedback loop between us and our students: We teach them out of these materials, and they respond to it. Without that loop, this book could never have existed, nor could it be maintained. If Big Nerd Ranch books are special (and we hope they are), it is that feedback loop that makes them so. Thank you.
Learning Android
As a beginning Android programmer, you face a steep learning curve. Learning Android is like moving to a foreign city. Even if you speak the language, it will not feel like home at first. Everyone around you seems to understand things that you are missing. Things you already knew turn out to be dead wrong in this new context.
Android has a culture. That culture speaks Kotlin or Java (or a bit of both), but knowing Kotlin or Java is not enough. Getting your head around Android requires learning many new ideas and techniques. It helps to have a guide through unfamiliar territory.
Thats where we come in. At Big Nerd Ranch, we believe that to be an Android programmer, you must:
This guide will help you do both. We have trained thousands of professional Android programmers using it. We will lead you through writing several Android applications, introducing concepts and techniques as needed. When there are rough spots, or when some things are tricky or obscure, you will face them head on, and we will do our best to explain why things are the way they are.
This approach allows you to put what you have learned into practice in a working app right away rather than learning a lot of theory and then having to figure out how to apply it all later. You will come away with the experience and understanding you need to get going as an Android developer.