Head First Android Development

Book description

What will you learn from this book?

If you have an idea for a killer Android app, this book will help you build your first working application in a jiffy. You’ll learn hands-on how to structure your app, design interfaces, create a database, make your app work on various smartphones and tablets, and much more. It’s like having an experienced Android developer sitting right next to you! All you need is some Java know-how to get started.

Why does this book look so different?

Based on the latest research in cognitive science and learning theory, Head First Android Development uses a visually rich format to engage your mind, rather than a text-heavy approach that puts you to sleep. Why waste your time struggling with new concepts? This multi-sensory learning experience is designed for the way your brain really works.

Publisher resources

View/Submit Errata

Table of contents

  1. Dedication
  2. Authors of Head First Android Development
  3. How to Use This Book: Intro
    1. Who is this book for?
      1. Who should probably back away from this book?
    2. We know what you’re thinking
    3. We know what your brain is thinking
    4. Metacognition: thinking about thinking
    5. Here’s what WE did:
    6. Here’s what YOU can do to bend your brain into submission
    7. Read me
    8. The technical review team
    9. Acknowledgments
    10. Safari® Books Online
  4. 1. Getting Started: Diving In
    1. Welcome to Androidville
      1. Layouts define what each screen looks like
      2. Java code defines what the app should do
      3. Sometimes extra resources are needed too
    2. The Android platform dissected
    3. Here’s what we’re going to do
    4. Your development environment
      1. The Android SDK
      2. Android Studio is a special version of IntelliJ IDEA
    5. Install Java
      1. Then install Android Studio
    6. Build a basic app
    7. Let’s build the basic app
      1. 1. Create a new project
      2. 2. Configure the project
      3. 3. Specify the API level
    8. Activities and layouts from 50,000 feet
    9. Building a basic app (continued)
      1. 4. Create an activity
    10. Building a basic app (continued)
      1. 5. Configure the activity
    11. You’ve just created your first Android app
    12. Android Studio creates a complete folder structure for you
      1. The folder structure includes different types of files
    13. Useful files in your project
    14. Edit code with the Android Studio editors
      1. The code editor
      2. The design editor
    15. Run the app in the Android emulator
      1. So what does the emulator look like?
    16. Creating an Android Virtual Device
      1. Open the Android Virtual Device Manager
      2. Select the hardware
      3. Select a system image
      4. Verify the AVD configuration
    17. Run the app in the emulator
      1. Compile, package, deploy and run
    18. You can watch progress in the console
    19. Test drive
    20. What just happened?
    21. Refining the app
      1. The app has one activity and one layout
      2. The activity controls what the app does
      3. The layout controls the app appearance
    22. What’s in the layout?
      1. The design editor
      2. The code editor
    23. activity_main.xml has two elements
    24. The layout file contains a reference to a string, not the string itself
    25. Let’s look in the strings.xml file
      1. Update strings.xml to change the text
    26. Take the app for a test drive
    27. Your Android Toolbox
  5. 2. Building Interactive Apps: Apps That Do Something
    1. You’re going to build a Beer Adviser app
    2. Here’s what you need to do
    3. Create the project
    4. We’ve created a default activity and layout
    5. Adding components with the design editor
      1. Changes in the design editor are reflected in the XML
    6. activity_find_beer.xml has a new button
      1. Buttons and text views are subclasses of the same Android View class
      2. android:id
      3. android:text
      4. android:layout_width, android:layout_height
    7. A closer look at the layout code
      1. The RelativeLayout element
      2. The TextView element
      3. The Button element
    8. Changes to the XML...
    9. ...are reflected in the design editor
    10. Use string resources rather than hardcoding the text
    11. Change the layout to use the string resources
    12. Let’s take the app for a test drive
      1. Here’s what we’ve done so far
    13. Add values to the spinner
      1. Adding an array resource is similar to adding a string
    14. Get the spinner to reference a string-array
    15. Test drive the spinner
    16. We need to make the button do something
    17. Make the button call a method
      1. Use onClick to say which method the button calls
    18. What activity code looks like
    19. Add an onClickFindBeer() method to the activity
    20. onClickFindBeer() needs to do something
      1. Use findViewById() to get a reference to a view
    21. Once you have a View, you can access its methods
      1. Setting the text in a TextView
      2. Retrieving the selected value in a spinner
    22. Update the activity code
    23. The first version of the activity
    24. What the code does
    25. Test drive the changes
    26. Building the custom Java class
      1. Custom Java class spec
      2. Build and test the Java class
    27. Enhance the activity to call the custom Java class so that we can get REAL advice
    28. Activity code version 2
    29. What happens when you run the code
    30. Test drive your app
    31. Your Android Toolbox
  6. 3. Multiple Activities and Intents: State Your Intent
    1. Apps can contain more than one activity
      1. Here are the steps
    2. Here’s the app structure
    3. Create the project
    4. Update the layout
    5. Update strings.xml...
      1. ... and add the method to the activity
    6. Create the second activity and layout
    7. What just happened?
    8. Welcome to the Android manifest file
    9. Every activity needs to be declared
    10. An intent is a type of message
    11. Use an intent to start the second activity
    12. What happens when you run the app
    13. The story continues...
    14. Test drive the app
    15. Pass text to a second activity
      1. Let’s start with the layout
    16. Update the text view properties
    17. putExtra() puts extra information in an intent
      1. How to retrieve extra information from an intent
    18. Update the CreateMessageActivity code
    19. Get ReceiveMessageActivity to use the information in the intent
    20. What happens when the user clicks the Send Message button
    21. Test drive the app
    22. We can change the app to send messages to other people
    23. How Android apps work
      1. Intents can start activities in other apps
    24. But we don’t know what apps are on the device
      1. Here’s what you’re going to do
    25. Create an intent that specifies an action
      1. How to create the intent
      2. Adding extra information
    26. Change the intent to use an action
    27. What happens when the code runs
    28. The story continues...
    29. The intent filter tells Android which activities can handle which actions
    30. How Android uses the intent filter
    31. You need to run your app on a REAL device
      1. 1. Enable USB debugging on your device
      2. 2. Set up your system to detect your device
      3. 3. Plug your device into your computer with a USB cable
      4. 4. Run your app in Android Studio as normal
      5. And here’s the app running on the physical device
    32. Test drive the app
      1. If you have one activity
      2. If you have more than one activity
    33. What if you ALWAYS want your users to choose an activity?
      1. Intent.createChooser() displays a chooser dialog
    34. What happens when you call createChooser()
    35. The story continues...
    36. Change the code to create a chooser
      1. Update strings.xml...
      2. ... and update the onSendMessage() method
    37. Test drive the app
      1. If you have one activity
      2. If you have more than one activity
    38. If you have NO matching activities
    39. Your Android Toolbox
  7. 4. The Activity Lifecycle: Being an Activity
    1. How do activities really work?
    2. The Stopwatch app
      1. Build the app
    3. The stopwatch layout code
      1. The stopwatch strings.xml file
    4. How the activity code will work
    5. Add code for the buttons
    6. The runTimer() method
    7. Handlers allow you to schedule code
      1. The post() method
      2. The postDelayed() method
    8. The full runTimer() code
    9. The full StopwatchActivity code
    10. What happens when you run the app
    11. The story continues
    12. Test drive the app
      1. But there’s just one problem...
    13. What just happened?
    14. Rotating the screen changes the device configuration
    15. From birth to death: the states of an activity
    16. The activity lifecycle: from create to destroy
    17. Your activity inherits the lifecycle methods
    18. How do we deal with configuration changes?
      1. Bypass re-creating the activity
    19. Or save the current state...
    20. ...then restore the state in onCreate()
    21. What happens when you run the app
    22. The story continues
    23. Test drive the app
    24. There’s more to an activity’s life than create and destroy
      1. Start, stop, and restart
    25. The activity lifecycle: the visible lifetime
    26. We need to implement two more lifecycle methods
      1. Implement onStop() to stop the timer
    27. The updated StopwatchActivity code
    28. What happens when you run the app
    29. Test drive the app
    30. But what if an app is only partially visible?
    31. The activity lifecycle: the foreground lifetime
    32. Stop the stopwatch if the activity’s paused
    33. What happens when you run the app
    34. Test drive the app
    35. The complete activity code
    36. Your handy guide to the lifecycle methods
    37. Your Android Toolbox
  8. 5. The User Interface: Enjoy the View
    1. Your user interface is made up of layouts and GUI components
    2. Three key layouts: relative, linear, and grid
      1. RelativeLayout
      2. LinearLayout
      3. GridLayout
    3. RelativeLayout displays views in relative positions
      1. You MUST set the layout width and height
    4. Adding padding
    5. Positioning views relative to the parent layout
    6. Attributes for positioning views relative to the parent layout
    7. Positioning views relative to other views
    8. Attributes for positioning views relative to other views
    9. Use margins to add distance between views
    10. RelativeLayout: a summary
      1. How you specify a relative layout
      2. You can position views relative to the layout of another view
      3. You can add margins to views to increase the space around them
    11. LinearLayout displays views in a single row or column
      1. How you define a linear layout
    12. A linear layout displays views in the order they appear in the layout XML
    13. Let’s change up a basic linear layout
    14. Here’s the starting point for the linear layout
    15. Make a view streeeeetch by adding weight
    16. Adding weight to one view
    17. Adding weight to multiple views
    18. Use gravity to specify where text appears in a view
    19. Test drive
    20. Using the android:gravity attribute: a list of values
    21. Move the button to the right with layout-gravity
    22. More values you can use with the android:layout-gravity attribute
    23. The full linear layout code
    24. LinearLayout: a summary
      1. How you specify a linear layout
      2. Views get displayed in the order they appear
      3. Stretch views using weight
      4. Use gravity to specify where a view’s contents appear in a view
      5. Use layout-gravity to specify where a view appears in its enclosing space
    25. GridLayout displays views in a grid
      1. How you define a grid layout
    26. Adding views to the grid layout
    27. Let’s create a new grid layout
      1. Here’s what we’re going to do
    28. We’ll start with a sketch
      1. The grid layout needs two columns
    29. Row 0: add views to specific rows and columns
    30. Row 1: make a view span multiple columns
    31. Row 2: make a view span multiple columns
    32. The full code for the grid layout
    33. GridLayout: a summary
      1. How you specify a grid layout
      2. Specify which row and column each view should start in
      3. Specify how many columns each view should span
    34. Layouts and GUI components have a lot in common
    35. GUI components are a type of View
      1. Layouts are a type of View called a ViewGroup
    36. What being a view buys you
      1. Getting and setting properties
      2. Size and position
      3. Focus handling
      4. Event handling and listeners
    37. A layout is really a hierarchy of Views
    38. Playing with views
    39. Text view
      1. Defining it in XML
      2. Using it in your activity code
    40. Edit Text
      1. Defining it in XML
      2. Using it in your activity code
    41. Button
      1. Defining it in XML
      2. Using it in your activity code
    42. Toggle button
      1. Defining it in XML
      2. Using it in your activity code
    43. Switch
      1. Defining it in XML
      2. Using it in your activity code
    44. Check boxes
      1. Defining them in XML
      2. Using them in your activity code
    45. Radio buttons
      1. Defining them in XML
      2. Using them in your activity code
    46. Spinner
      1. Defining it in XML
      2. Using it in your activity code
    47. Image views
      1. Adding an image to your project
    48. Images: the layout XML
      1. Using it in your activity code
    49. Adding images to buttons
      1. Displaying text and an image on a button
    50. Image Button
      1. Defining it in XML
      2. Using it in your activity code
    51. Scroll views
    52. Toasts
      1. Using it in your activity code
    53. Your Android Toolbox
  9. 6. List Views and Adapters: Getting Organized
    1. Every app starts with ideas
    2. Categorize your ideas: top-level, category, and detail/edit activities
      1. Top-level activities
      2. Category activities
      3. Detail/edit activities
    3. Navigating through the activities
      1. Top-level activities go at the top
      2. Category activities go between top-level and detail/edit activities
      3. Detail/edit activities
    4. Use ListViews to navigate to data
    5. We’re going to build part of the Starbuzz app
      1. The top-level activity
      2. The drinks category activity
    6. The drink detail activity
      1. How the user navigates through the app
    7. The Starbuzz app structure
    8. Here are the steps
      1. Create the project
    9. The Drink class
    10. The image files
    11. The top-level layout contains an image and a list
    12. Use a list view to display the list of options
      1. How to define a list view in XML
    13. The full top-level layout code
    14. Test drive
    15. Get ListViews to respond to clicks with a Listener
      1. OnItemClickListener listens for item clicks
    16. Set the listener to the list view
      1. What happens when you run the code
    17. The full TopLevelActivity code
    18. Where we’ve got to
    19. A category activity displays the data for a single category
    20. A ListActivity is an activity that contains only a list
    21. How to create a list activity
    22. android:entries works for static array data held in strings.xml
      1. For nonstatic data, use an adapter
    23. Connect list views to arrays with an array adapter
    24. Add the array adapter to DrinkCategoryActivity
    25. What happens when you run the code
    26. Test drive the app
    27. App review: where we’ve got to
    28. How we handled clicks in TopLevelActivity
      1. ListActivity implements an item click listener by default
    29. Pass data to an activity using the ListActivity onListItemClick() method
    30. The full DrinkCategoryActivity code
    31. A detail activity displays data for a single record
    32. Retrieve data from the intent
    33. Update the views with the data
    34. The DrinkActivity code
    35. What happens when you run the app
    36. The story continues
    37. Test drive the app
    38. Your Android Toolbox
  10. 7. Fragments: Make it Modular
    1. Your app needs to look great on all devices
      1. On a phone:
      2. On a tablet:
    2. Your app may need to behave differently too
      1. On a phone:
      2. On a tablet:
      3. But that means you might duplicate code
    3. Fragments allow you to reuse code
      1. A fragment has a layout
    4. The Workout app structure
    5. Here are the steps
      1. Create the project
    6. The Workout class
    7. How to add a fragment to your project
    8. Fragment layout code looks just like activity layout code
    9. What fragment code looks like
    10. Adding a fragment to an activity’s layout
    11. Passing the workout ID to the fragment
    12. Get the activity to set the workout ID
    13. Activity states revisited
    14. The fragment lifecycle
    15. Your fragment inherits the lifecycle methods
    16. Set the view’s values in the fragment’s onStart() method
    17. Test drive the app
      1. What happens when you run the app
    18. Where we’ve got to
    19. We need to create a fragment with a list
    20. A ListFragment is a fragment that contains only a list
    21. How to create a list fragment
    22. We’ll use an ArrayAdapter to set the values in the ListView
      1. A Fragment isn’t a type of Context
    23. The updated WorkoutListFragment code
    24. Display WorkoutListFragment in the MainActivity layout
    25. Test drive the app
      1. We need to get WorkoutDetailFragment to respond to clicks in WorkoutListFragment
    26. Wiring up the list to the detail
    27. We need to decouple the fragment with an interface
      1. But when will the activity say that it’s listening?
    28. First, add the interface to the list fragment
    29. Then make the activity implement the interface
      1. But how do we update the workout details?
    30. You want fragments to work with the back button
      1. Welcome to the back stack
    31. Don’t update—instead, replace
    32. Using fragment transactions
    33. The updated MainActivity code
    34. Test drive the app
    35. Rotating the device breaks the app
    36. The WorkoutDetailFragment code
    37. Phone versus tablet
      1. On a tablet
      2. On a phone
    38. The phone and tablet app structures
      1. On a tablet
      2. On a phone
    39. Put screen-specific resources in screen-specific folders
    40. The different folder options
    41. Tablets use layouts in the layout-large folder
    42. The MainActivity phone layout
    43. Phones will use DetailActivity to display details of the workout
    44. The full DetailActivity code
    45. Use layout differences to tell which layout the device is using
    46. The revised MainActivity code
    47. Test drive the app
    48. Your Android Toolbox
      1. Fragment Lifecycle Methods
  11. 8. Nested Fragments: Dealing with Children
    1. Creating nested fragments
      1. We’ll add a new stopwatch fragment
    2. Fragments and activities have similar lifecycles...
      1. ... but the methods are slightly different
    3. The StopwatchFragment code
    4. The StopwatchFragment layout
      1. The StopwatchFragment layout uses String values
    5. Adding the stopwatch fragment to WorkoutDetailFragment
      1. We need to add it programmatically
    6. Add a FrameLayout where the fragment should appear
    7. Then display the fragment in Java code
    8. getFragmentManager() creates transactions at the activity lavel
      1. Beware the back button
    9. Nested fragments need nested transactions
    10. Display the fragment in its parent’s onCreate() method
    11. The full WorkoutDetailFragment code
    12. Test drive the app
      1. But there’s a problem if you try to interact with the stopwatch
    13. Why does the app crash if you press a button?
    14. Let’s look at the StopwatchFragment layout code
    15. The onClick attribute calls methods in the activity, not the fragment
      1. How to make button clicks call methods in the fragment
    16. First, remove the onClick attributes from the fragment’s layout
    17. Make the fragment implement OnClickListener
      1. The StopwatchFragment onClick() method
    18. Attach the OnClickListener to the buttons
    19. The StopwatchFragment code
    20. Test drive the app
      1. But there’s a problem when you rotate the device
    21. Rotating the device re-creates the activity
      1. What happens to the fragment when you rotate the device
    22. onCreate() REPLACES the fragment
    23. The WorkoutDetailFragment code
    24. Test drive the app
    25. Your Android Toolbox
  12. 9. Action Bars: Taking Shortcuts
    1. Great apps have a clear structure
      1. Top-level screens
      2. Category screens
      3. Detail/edit screens
      4. They also have great shortcuts
    2. Different types of navigation
      1. Using actions for navigation
    3. Let’s start with the action bar
      1. API level 11 and above
      2. API level 7 or above
    4. The Android support libraries
    5. Your project may include support libraries
    6. We’ll get the app to use up to date themes
      1. Change MainActivity to use an Activity
    7. Apply a theme in AndroidManifest.xml
    8. Define styles in style resource files
    9. Set the default theme in styles.xml
      1. Use a Material theme on newer devices
    10. What happens when you run the app
    11. Test drive the app
    12. Adding action items to the action bar
    13. The menu resource file
    14. The menu showAsAction attribute
    15. Add a new action item
    16. Inflate the menu in the activity with the onCreateOptionsMenu() method
    17. React to action item clicks with the onOptionsItemSelected() method
    18. Create OrderActivity
    19. Start OrderActivity with the Create Order action item
    20. The full MainActivity.java code
    21. Test drive the app
    22. Sharing content on the action bar
      1. You share the content with an intent
    23. Add a share action provider to menu_main.xml
    24. Specify the content with an intent
    25. The full MainActivity.java code
    26. Test drive the app
    27. Enabling Up navigation
    28. Setting an activity’s parent
    29. Adding the Up button
    30. Test drive the app
    31. Your Android Toolbox
  13. 10. Navigation Drawers: Going Places
    1. The Pizza app revisited
    2. Navigation drawers deconstructed
    3. The Pizza app structure
    4. Create TopFragment
    5. Create PizzaFragment
    6. Create PastaFragment
    7. Create StoresFragment
    8. Add the DrawerLayout
    9. The full code for activity_main.xml
    10. Initialize the drawer’s list
    11. Use an OnItemClickListener to respond to clicks in the list view
    12. The selectItem() method so far
    13. Changing the action bar title
    14. Closing the navigation drawer
    15. The updated MainActivity.java code
    16. Get the drawer to open and close
    17. Using an ActionBarDrawerToggle
    18. Modifying action bar items at runtime
    19. The updated MainActivity.java code
    20. Enable the drawer to open and close
    21. Syncing the ActionBarDrawerToggle state
    22. The updated MainActivity.java code
    23. Test drive the app
    24. The title and fragment are getting out of sync
    25. Dealing with configuration changes
    26. Reacting to changes on the back stack
    27. Adding tags to fragments
    28. Find the fragment using its tag
    29. The full MainActivity.java code
    30. Test drive the app
    31. Your Android Toolbox
  14. 11. SQLite Databases: Fire Up the Database
    1. Back to Starbuzz
    2. Android uses SQLite databases to persist data
      1. Where’s the database stored?
    3. Android comes with SQLite classes
      1. The SQLite Helper
      2. Cursors
      3. The SQLite Database
    4. The current Starbuzz app structure
    5. We’ll change the app to use a database
    6. The SQLite helper manages your database
    7. Create the SQLite helper
    8. 1. Specify the database
    9. Inside a SQLite database
      1. Storage classes and data-types
    10. You create tables using Structured Query Language (SQL)
      1. The onCreate() method is called when the database is created
    11. Insert data using the insert() method
    12. Update records with the update() method
    13. Multiple conditions
      1. Delete records with the delete() method
    14. The StarbuzzDatabaseHelper code
    15. What the SQLite helper code does
    16. What if you need to change the database?
    17. SQLite databases have a version number
    18. Upgrading the database: an overview
    19. The story continues....
    20. How the SQLite helper makes decisions
    21. Upgrade your database with onUpgrade()
    22. Downgrade your database with onDowngrade()
    23. Let’s upgrade the database
    24. Upgrading an existing database
      1. Add new columns to tables using SQL
    25. Renaming tables
      1. Delete tables by dropping them
      2. Execute the SQL using execSQL()
    26. The full SQLite helper code
    27. The SQLite helper code (continued)
    28. What happens when the code runs
    29. Your Android Toolbox
  15. 12. Cursors and Asynctasks: Connecting to Databases
    1. The story so far...
    2. We’ll change the app to use the database
    3. The current DrinkActivity code
    4. Get data from the database with a cursor
      1. Cursors give you access to database data
    5. A query lets you say what records you want from the database
      1. Specify the table and columns
      2. Declare any conditions that restrict your selection
      3. Other stuff you can use queries for
    6. The SQLiteDatabase query() method lets you build SQL using a query builder
    7. Specifying table and columns
      1. Restrict your query by applying conditions
    8. Applying multiple conditions to your query
      1. You specify conditions as String values
    9. Order data in your query
    10. Using SQL functions in queries
    11. SQL GROUP BY and HAVING clauses
    12. Get a reference to the database
    13. getReadableDatabase() versus getWritableDatabase()
    14. getReadableDatabase()
    15. getWritableDatabase()
    16. The code for getting a cursor
      1. What the code does
    17. To read a record from a cursor, you first need to navigate to it
    18. Navigating cursors
    19. Getting cursor values
      1. Finally, close the cursor and database
    20. The DrinkActivity code
    21. What we’ve done so far
    22. The current DrinkCategoryActivity code
    23. How do we replace the array data in the ListView?
    24. A CursorAdapter reads just enough data
    25. The story continues
    26. A SimpleCursorAdapter maps data to views
      1. First, create the cursor
    27. Creating the SimpleCursorAdapter
    28. Closing the cursor and database
    29. The revised code for DrinkCategoryActivity
    30. Test drive the app
      1. Where we’ve got to
    31. Put important information in the top-level activity
    32. Add favorites to DrinkActivity
    33. Add a new column to the cursor
    34. Respond to clicks to update the database
    35. The DrinkActivity code
    36. Display favorites in TopLevelActivity
    37. Display the favorite drinks in activity_top_level.xml
    38. What changes are needed for TopLevelActivity.java
    39. The new top-level activity code
    40. Test drive the app
    41. Cursors don’t automatically refresh
    42. Change the cursor with changeCursor()
    43. The revised TopLevelActivity.java code
    44. Test drive the app
    45. Databases can make your app go in sloooo-moooo....
      1. Life is better when threads work together
    46. What code goes on which thread?
    47. AsyncTask performs asynchronous tasks
    48. The onPreExecute() method
    49. The doInBackground() method
    50. The onProgressUpdate() method
    51. The onPostExecute() method
    52. The AsyncTask class
    53. Execute the AsyncTask
    54. The DrinkActivity.java code
    55. A summary of the AsyncTask steps
    56. Your Android Toolbox
  16. 13. Services: At Your Service
    1. Services work behind the scenes
      1. There are two types of service
    2. The started service app
      1. Create the project
    3. We’re going to create an IntentService
    4. The IntentService from 50,000 feet
    5. How to log messages
    6. The full DelayedMessageService code
    7. You declare services in AndroidManifest.xml
    8. Add a button to activity_main.xml
    9. You start a service using startService()
    10. Test drive the app
    11. We want to send a message to the screen
      1. Screen updates require the main thread
    12. onStartCommand() runs on the main thread
    13. The full DelayedMessageService.java code
    14. The application context
    15. Test drive the app
    16. Can we improve on using Toasts?
    17. How you use the notification service
    18. You create notifications using a notification builder
    19. Getting your notification to start an activity
      1. 1. Create an explicit intent
      2. 2. Pass the intent to the TaskStackBuilder
      3. 3. Get the pending intent from the TaskStackBuilder
      4. 4. Add the intent to the notification
    20. Send the notification using the notification service
    21. The full code for DelayedMessageService.java
    22. What happens when you run the code
    23. The story continues
    24. Test drive the app
    25. Bound services are more interactive
      1. How the odometer app will work
    26. The steps needed to create the OdometerService
    27. Create a new Odometer project
    28. How binding works
    29. Define the Binder
    30. Get the service to do something
    31. The Service class has four key methods
    32. Location, location, location...
    33. Add the LocationListener to the service
    34. Registering the LocationListener
    35. Stop location updates when the service is destroyed
    36. Tell the activity the distance traveled
    37. The full OdometerService.java code
    38. Update AndroidManifest.xml
    39. Where we’ve got to
    40. Update MainActivity’s layout
    41. Create a ServiceConnection
    42. Bind to the service when the activity starts
      1. Unbind from the service when the activity stops
    43. Display the distance traveled
    44. The full MainActivity.java code
    45. What happens when you run the code
    46. The story continues
    47. Test drive the app
    48. Your Android Toolbox
  17. 14. Material Design: Living in a Material World
    1. Welcome to Material Design
    2. CardViews and RecyclerViews
      1. from this:
      2. to this:
    3. The Pizza app structure
    4. Add the pizza data
      1. Add the Pizza class
    5. Add the support libraries
    6. Create the CardView
    7. The full card_captioned_image.xml code
    8. RecyclerViews use RecyclerView.Adapters
    9. Create the basic adapter
    10. Define the adapter’s ViewHolder
    11. Create the ViewHolders
    12. Each card view displays an image and a caption
      1. Create the constructor
    13. Add the data to the card views
    14. The full code for CaptionedImagesAdapter.java
    15. Create the recycler view
    16. Add the RecyclerView to the layout
      1. Using the adapter
    17. The PizzaMaterialFragment.java code
    18. A RecyclerView uses a layout manager to arrange its views
    19. Specifying the layout manager
    20. The full PizzaMaterialFragment.java code
    21. Get MainActivity to use the new PizzaMaterialFragment
    22. What happens when the code runs
    23. The story continues
    24. Test drive the app
    25. Where we’ve got to
    26. Create PizzaDetailActivity
    27. What PizzaDetailActivity.java needs to do
      1. Update AndroidManifest.xml
    28. The code for PizzaDetailActivity.java
    29. Getting a RecyclerView to respond to clicks
    30. You can listen to views from the adapter
    31. Keep your adapters reusable
      1. Decouple your adapter with an interface
    32. Add the interface to the adapter
    33. Implement the listener in PizzaMaterialFragment.java
    34. Test drive the app
    35. Bring the content forward
    36. The full code for fragment_top.xml
    37. The full code for TopFragment.java
    38. Test drive the app
    39. Your Android Toolbox
  18. I. Leaving town...
    1. A. ART: The Android Runtime
      1. What is the Android runtime (ART)?
        1. ART is very different from the JVM
        2. How Android runs an APK file
      2. Performance and size
        1. Security
    2. B. ADB: The Android Debug Bridge
      1. adb: your command-line pal
      2. Running a shell
      3. Get the output from logcat
        1. Copying files to/from your device
      4. And much, much more...
    3. C. The Emulator: The Android Emulator
      1. Why the emulator is so slow
      2. How to speed up your Android development
        1. 1. Use a real device
        2. 2. Use an emulator snapshot
        3. 3. Use hardware acceleration
    4. D. Leftovers: The Top Ten Things (we didn’t cover)
      1. 1. Distributing your app
        1. Preparing your app for release
        2. Releasing your app
      2. 2. Content providers
      3. 3. The WebView class
      4. 4. Animation
        1. Property animation
        2. View animations
        3. Activity transitions
      5. 5. Maps
      6. 6. Cursor loaders
      7. 7. Broadcast receivers
      8. 8. App widgets
      9. 9. NinePatch graphics
      10. 10. Testing
  19. E. O’reilly®: Android Development
    1. What will you learn from this book?
    2. Why does this book look so different?
  20. Index
  21. About the Authors
  22. Copyright

Product information

  • Title: Head First Android Development
  • Author(s): Dawn Griffiths, David Griffiths
  • Release date: June 2015
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449362188