Head First Android Development free PDF

Posted by payamprivate

Head First Android Development free PDF

eBook Description:

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 Head First Android Development 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.


Table of contents:

  1. Chapter 1 Getting Started: Diving In

    1. Welcome to Androidville

    2. The Android platform dissected

    3. Here’s what we’re going to do

    4. Your development environment

    5. Install Java

    6. Build a basic app

    7. Let’s build the basic app

    8. Activities and layouts from 50,000 feet

    9. Building a basic app (continued)

    10. Building a basic app (continued)

    11. You’ve just created your first Android app

    12. Android Studio creates a complete folder structure for you

    13. Useful files in your project

    14. Edit code with the Android Studio editors

    15. Run the app in the Android emulator

    16. Creating an Android Virtual Device

    17. Run the app in the emulator

    18. You can watch progress in the console

    19. Test drive

    20. What just happened?

    21. Refining the app

    22. What’s in the layout?

    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

    26. Take the app for a test drive

    27. Your Android Toolbox

  2. Chapter 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

    6. activity_find_beer.xml has a new button

    7. A closer look at the layout code

    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

    13. Add values to the spinner

    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

    18. What activity code looks like

    19. Add an onClickFindBeer() method to the activity

    20. onClickFindBeer() needs to do something

    21. Once you have a View, you can access its methods

    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

    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

  3. Chapter 3 Multiple Activities and Intents: State Your Intent

    1. Apps can contain more than one activity

    2. Here’s the app structure

    3. Create the project

    4. Update the layout

    5. Update strings.xml…

    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

    16. Update the text view properties

    17. putExtra() puts extra information in 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

    24. But we don’t know what apps are on the device

    25. Create an intent that specifies an action

    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

    32. Test drive the app

    33. What if you ALWAYS want your users to choose an activity?

    34. What happens when you call createChooser()

    35. The story continues…

    36. Change the code to create a chooser

    37. Test drive the app

    38. If you have NO matching activities

    39. Your Android Toolbox

  4. Chapter 4 The Activity Lifecycle: Being an Activity

    1. How do activities really work?

    2. The Stopwatch app

    3. The stopwatch layout code

    4. How the activity code will work

    5. Add code for the buttons

    6. The runTimer() method

    7. Handlers allow you to schedule code

    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

    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?

    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

    25. The activity lifecycle: the visible lifetime

    26. We need to implement two more lifecycle methods

    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

  5. Chapter 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

    3. RelativeLayout displays views in relative positions

    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

    11. LinearLayout displays views in a single row or column

    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

    25. GridLayout displays views in a grid

    26. Adding views to the grid layout

    27. Let’s create a new grid layout

    28. We’ll start with a sketch

    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

    34. Layouts and GUI components have a lot in common

    35. GUI components are a type of View

    36. What being a view buys you

    37. A layout is really a hierarchy of Views

    38. Playing with views

    39. Text view

    40. Edit Text

    41. Button

    42. Toggle button

    43. Switch

    44. Check boxes

    45. Radio buttons

    46. Spinner

    47. Image views

    48. Images: the layout XML

    49. Adding images to buttons

    50. Image Button

    51. Scroll views

    52. Toasts

    53. Your Android Toolbox

  6. Chapter 6 List Views and Adapters: Getting Organized

    1. Every app starts with ideas

    2. Categorize your ideas: top-level, category, and detail/edit activities

    3. Navigating through the activities

    4. Use ListViews to navigate to data

    5. We’re going to build part of the Starbuzz app

    6. The drink detail activity

    7. The Starbuzz app structure

    8. Here are the steps

    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

    13. The full top-level layout code

    14. Test drive

    15. Get ListViews to respond to clicks with a Listener

    16. Set the listener to the list view

    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

    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

    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

  7. Chapter 7 Fragments: Make it Modular

    1. Your app needs to look great on all devices

    2. Your app may need to behave differently too

    3. Fragments allow you to reuse code

    4. The Workout app structure

    5. Here are the steps

    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

    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

    23. The updated WorkoutListFragment code

    24. Display WorkoutListFragment in the MainActivity layout

    25. Test drive the app

    26. Wiring up the list to the detail

    27. We need to decouple the fragment with an interface

    28. First, add the interface to the list fragment

    29. Then make the activity implement the interface

    30. You want fragments to work with the back button

    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

    38. The phone and tablet app structures

    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

  8. Chapter 8 Nested Fragments: Dealing with Children

    1. Creating nested fragments

    2. Fragments and activities have similar lifecycles…

    3. The StopwatchFragment code

    4. The StopwatchFragment layout

    5. Adding the stopwatch fragment to WorkoutDetailFragment

    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

    9. Nested fragments need nested transactions

    10. Display the fragment in its parent’s onCreateView() method

    11. The full WorkoutDetailFragment code

    12. Test drive the app

    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

    16. First, remove the onClick attributes from the fragment’s layout

    17. Make the fragment implement OnClickListener

    18. Attach the OnClickListener to the buttons

    19. The StopwatchFragment code

    20. Test drive the app

    21. Rotating the device re-creates the activity

    22. onCreateView() runs AFTER the transactions have been replayed

    23. The WorkoutDetailFragment code

    24. Test drive the app

    25. Your Android Toolbox

  9. Chapter 9 Action Bars: Taking Shortcuts

    1. Great apps have a clear structure

    2. Different types of navigation

    3. Let’s start with the action bar

    4. The Android support libraries

    5. Your project may include support libraries

    6. We’ll get the app to use up to date themes

    7. Apply a theme in AndroidManifest.xml

    8. Define styles in style resource files

    9. Set the default theme in styles.xml

    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

    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

  10. Chapter 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

  11. Chapter 11 SQLite Databases: Fire Up the Database

    1. Back to Starbuzz

    2. Android uses SQLite databases to persist data

    3. Android comes with SQLite classes

    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

    10. You create tables using Structured Query Language (SQL)

    11. Insert data using the insert() method

    12. Update records with the update() method

    13. Multiple conditions

    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

    25. Renaming tables

    26. The full SQLite helper code

    27. The SQLite helper code (continued)

    28. What happens when the code runs

    29. Your Android Toolbox

  12. Chapter 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

    5. A query lets you say what records you want from the database

    6. The SQLiteDatabase query() method lets you build SQL using a query builder

    7. Specifying table and columns

    8. Applying multiple conditions to your query

    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

    17. To read a record from a cursor, you first need to navigate to it

    18. Navigating cursors

    19. Getting cursor values

    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

    27. Creating the SimpleCursorAdapter

    28. Closing the cursor and database

    29. The revised code for DrinkCategoryActivity

    30. Test drive the app

    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….

    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

  13. Chapter 13 Services: At Your Service

    1. Services work behind the scenes

    2. The started service app

    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

    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

    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

    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. Tell the activity the distance traveled

    36. The full OdometerService.java code

    37. Update AndroidManifest.xml

    38. Where we’ve got to

    39. Update MainActivity’s layout

    40. Create a ServiceConnection

    41. Bind to the service when the activity starts

    42. Display the distance traveled

    43. The full MainActivity.java code

    44. What happens when you run the code

    45. The story continues

    46. Test drive the app

    47. Your Android Toolbox

  14. Chapter 14 Material Design: Living in a Material World

    1. Welcome to Material Design

    2. CardViews and RecyclerViews

    3. The Pizza app structure

    4. Add the pizza data

    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

    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

    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

    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

    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

  15. Leaving town…

    1. Appendix ART: The Android Runtime

      1. What is the Android runtime (ART)?
      2. Performance and size
    2. Appendix ADB: The Android Debug Bridge

      1. adb: your command-line pal
      2. Running a shell
      3. Get the output from logcat
      4. And much, much more…
    3. Appendix The Emulator: The Android Emulator

      1. Why the emulator is so slow
      2. How to speed up your Android development
    4. Appendix Leftovers: The Top Ten Things (we didn’t cover)

      1. 1. Distributing your app
      2. 2. Content providers
      3. 3. The WebView class
      4. 4. Animation
      5. 5. Maps
      6. 6. Cursor loaders
      7. 7. Broadcast receivers
      8. 8. App widgets
      9. 9. NinePatch graphics
      10. 10. Testing
  1. Appendix O’reilly®: Android Development
    1. What will you learn from this book?
    2. Why does this book look so different?


eBook Details:

Published by: O'Reilly Media
Date Published: 06/10/2015
ISBN: 978-1-4493-6213-3
Available in: PDF


eBook Download Link:


Read Online Now Link :



  • It works. Thanks

  • thanks a lot for this one….

  • Great!! thank you

  • thanks a lot

  • thanks a lot !

  • Downloading not done…..

    • Hi dear , download link fixed 🙂

  • can anyone provide me the software link used in this book. I want do get some hands on experience.

  • the problem my dear sir does not look fixed to me

  • Thank you very much bro !

  • Thanks.
    Good Job…

  • I thank you a lot… May GOD Almighty bless you…

  • Thank you.. 🙂

Leave a Reply

Your email address will not be published.