0%

Learn the Java and Android skills you need to start developing powerful mobile applications with the help of actionable steps

Key Features

  • Kick-start your Android programming career or just have fun publishing apps to the Google Play marketplace
  • Get a first principles introduction to using Java and Android and prepare to start building your own apps from scratch
  • Learn by example by building four real-world apps and dozens of mini apps

Book Description

Do you want to make a career in programming but don't know where to start? Do you have a great idea for an app but don't know how to make it a reality? Or are you worried that you'll have to learn Java programming to become an Android developer? Look no further! This new and expanded third edition of Android Programming for Beginners will be your guide to creating Android applications from scratch.

The book starts by introducing you to all the fundamental concepts of programming in an Android context, from the basics of Java to working with the Android API. You'll learn with the help of examples that use up-to-date API classes and are created within Android Studio, the official Android development environment that helps supercharge your mobile application development process. After a crash course on the key programming concepts, you'll explore Android programming and get to grips with creating applications with a professional-standard UI using fragments and storing user data with SQLite. This Android Java book also shows you how you can make your apps multilingual, draw on the screen with a finger, and work with graphics, sound, and animations.

By the end of this Android programming book, you'll be ready to start building your own custom applications in Android and Java.

What you will learn

  • Understand the fundamentals of coding in Java for Android
  • Install and set up your Android development environment
  • Build functional user interfaces with the Android Studio visual designer
  • Add user interaction, data captures, sound, and animation to your apps
  • Manage your apps' data using the built-in Android SQLite database
  • Explore the design patterns used by professionals to build top-grade applications
  • Build real-world Android applications that you can deploy to the Google Play marketplace

Who this book is for

This Android book is for you if you are completely new to Java, Android, or programming and want to get started with Android app development. If you have experience of using Java on Android, this book will serve as a refresher to help you advance your knowledge and make progress through the early projects covered in the book.

Table of Contents

  1. Android Programming for Beginners – Third Edition
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  6. Chapter 1: Beginning Android and Java
    1. Technical requirements
    2. What's new in the third edition?
    3. Why Java and Android?
    4. The beginner's first stumbling block
    5. How Java and Android work together
    6. Understanding the Android API
    7. Java is object-oriented
    8. Run that by me again – what exactly is Android?
    9. Android Studio
    10. Setting up Android Studio
    11. What makes an Android app?
    12. Android resources
    13. The structure of Android's Java code
    14. Packages
    15. Classes
    16. Methods
    17. Building our first Android app
    18. Deploying the app so far
    19. Running and debugging the app on an Android emulator
    20. Running the app on a real device
    21. Frequently asked questions
    22. Summary
  7. Chapter 2: First Contact: Java, XML, and the UI Designer
    1. Technical requirements
    2. Examining the logcat output
    3. Filtering the logcat output
    4. Exploring the project Java and the main layout XML
    5. Examining the MainActivity.java file
    6. Examining the app layout file
    7. Adding buttons to the main layout file
    8. Adding a button via the visual designer
    9. Adding a button by editing the XML code
    10. Giving the buttons unique id attributes
    11. Positioning the two buttons in the layout
    12. Making the buttons call different methods
    13. Leaving comments in our Java code
    14. Coding messages to the user and the developer
    15. Writing our first Java code
    16. Adding message code to the onCreate method
    17. Writing our own Java methods
    18. Frequently asked questions
    19. Summary
  8. Chapter 3: Exploring Android Studio and the Project Structure
    1. Technical requirements
    2. Project Explorer and project anatomy
    3. Exploring the file and folder structure of the Empty Activity project template
    4. Exploring an Empty Activity project
    5. Exploring the file and folder structure of the Basic Activity project template
    6. Exploring a Basic Activity project
    7. Exploring the Android emulator
    8. Emulator control panel
    9. Using the emulator as a real device
    10. Summary
  9. Chapter 4: Getting Started with Layouts and Material Design
    1. Technical requirements
    2. Finding out about Material Design
    3. Exploring Android UI design
    4. Introducing layouts
    5. Creating and exploring a layout project
    6. Building a layout with LinearLayout
    7. Adding a LinearLayout layout type to a project
    8. Preparing your workspace
    9. Examining the generated XML
    10. Adding a TextView to the UI
    11. Wiring up the UI with the Java code (Part 1)
    12. Adding layouts within layouts
    13. Making the layout look pretty
    14. Wiring up the UI with Java code (Part 2)
    15. Building a precise UI with ConstraintLayout
    16. Adding a CalendarView
    17. Adding and constraining more UI elements
    18. Making the text clickable
    19. Laying out data with TableLayout
    20. Adding a TableRow element to TableLayout
    21. Organizing the table columns
    22. Linking back to the main menu
    23. Summary
  10. Chapter 5: Beautiful Layouts with CardView and ScrollView
    1. Technical requirements
    2. Attributes quick summary
    3. Sizing using dp
    4. Sizing fonts using sp
    5. Determining size with wrap or match
    6. Using padding and margin
    7. Using the layout_weight property
    8. Using gravity
    9. Building a UI with CardView and ScrollView
    10. Setting the view with Java code
    11. Adding image resources
    12. Creating the contents for the cards
    13. Defining dimensions for CardView
    14. Adding CardView to our layout
    15. Creating a tablet emulator
    16. Frequently asked question
    17. Summary
  11. Chapter 6: The Android Lifecycle
    1. Technical requirements
    2. The life and times of an Android app
    3. How Android interacts with our apps
    4. A simplified explanation of the Android lifecycle
    5. The lifecycle phases demystified
    6. How we handle the lifecycle phases
    7. Lifecycle demo app
    8. Coding the lifecycle demo app
    9. Running the lifecycle demo app
    10. Examining the lifecycle demo app output
    11. Some other overridden methods
    12. The structure of Java code – revisited
    13. Introducing fragments and the lifecycle
    14. Summary
  12. Chapter 7: Java Variables, Operators, and Expressions
    1. Technical requirements
    2. Java is everywhere
    3. Understanding Java syntax and jargon
    4. More code comments
    5. Storing and using data with variables
    6. Types of variables
    7. Using variables
    8. Variable declaration
    9. Variable initialization
    10. Changing values in variables with operators
    11. The assignment operator
    12. The addition operator
    13. The subtraction operator
    14. The division operator
    15. The multiplication operator
    16. The increment operator
    17. The decrement operator
    18. Trying out expressions
    19. Expressing Yourself demo app
    20. Summary
  13. Chapter 8: Java Decisions and Loops
    1. Technical requirements
    2. Making decisions in Java
    3. Indenting code for clarity
    4. More operators
    5. How to use all these operators to test variables
    6. Switching to make decisions
    7. The switch demo app
    8. Repeating code with loops
    9. while loops
    10. do while loops
    11. for loops
    12. Loops demo app
    13. Summary
  14. Chapter 9: Learning Java Methods
    1. Technical requirements
    2. Methods revisited
    3. What exactly are Java methods?
    4. Method structure
    5. Modifier
    6. Return type
    7. Name of the method
    8. Parameters
    9. The body
    10. Using method demo apps
    11. Real-world methods
    12. Exploring method overloading
    13. Scope and variables revisited
    14. Method recursion
    15. Questions
    16. Summary
    17. Further reading
  15. Chapter 10: Object-Oriented Programming
    1. Technical requirements
    2. Important memory management warning
    3. Object-oriented programming
    4. What is OOP exactly?
    5. Why do it like this?
    6. Class recap
    7. Looking at the code for a class
    8. Class implementation
    9. Declaring, initializing, and using an object of the class
    10. Basic classes app
    11. More things we can do with our first class
    12. Frequently asked questions
    13. Summary
  16. Chapter 11: More Object-Oriented Programming
    1. Technical requirements
    2. Remember that encapsulation thing?
    3. Controlling class use with access modifiers
    4. Controlling variable use with access modifiers
    5. Methods can have access modifiers too
    6. Accessing private variables with getters and setters
    7. Setting up our objects with constructors
    8. Static methods
    9. Encapsulation and static methods mini-app
    10. OOP and inheritance
    11. Inheritance example app
    12. Polymorphism
    13. Abstract classes
    14. Interfaces
    15. Frequently asked questions
    16. Summary
  17. Chapter 12: The Stack, the Heap, and the Garbage Collector
    1. Technical requirements
    2. All the Android UI elements are classes too
    3. Re-introducing references
    4. So how does this heap thing help me?
    5. Using buttons and TextView widgets from our layout
    6. Running the app
    7. Inner and anonymous classes
    8. Frequently asked questions
    9. Summary
  18. Chapter 13: Anonymous Classes – Bringing Android Widgets to Life
    1. Technical requirements
    2. Declaring and initializing the objects
    3. Creating UI widgets from pure Java without XML
    4. Exploring the palette – part 1
    5. The EditText widget
    6. The ImageView widget
    7. Radio buttons and groups
    8. Anonymous classes
    9. Exploring the palette and more anonymous classes – part 2
    10. Switch
    11. CheckBox
    12. TextClock
    13. Using WebView
    14. The Widget Exploration app
    15. Setting up the Widget Exploration project and UI
    16. Coding the Widget Exploration app
    17. Using WebView
    18. Running the Widget Exploration app
    19. Summary
  19. Chapter 14: Android Dialog Windows
    1. Technical requirements
    2. Dialog windows
    3. Creating the Dialog Demo project
    4. Coding a DialogFragment class
    5. Using the DialogFragment class
    6. The Note to Self app
    7. Using naming conventions and string resources
    8. How to get the code files for the Note to Self app
    9. The completed app
    10. Building the project
    11. Preparing the string resources
    12. Coding the Note class
    13. Implementing the dialog designs
    14. Coding the dialog boxes
    15. Showing our new dialogs
    16. Summary
  20. Chapter 15: Arrays, Maps, and Random Numbers
    1. Technical requirements
    2. A random diversion
    3. Handling large amounts of data with arrays
    4. Arrays are objects
    5. Simple array example mini-app
    6. Getting dynamic with arrays
    7. Dynamic array example
    8. Entering the nth dimension with arrays
    9. Multidimensional array mini-app
    10. Array-out-of-bounds exceptions
    11. ArrayList
    12. The enhanced for loop
    13. Arrays and ArrayList instances are polymorphic
    14. More Java collections – meet the Java HashMap
    15. The Note to Self app
    16. Frequently asked questions
    17. Summary
  21. Chapter 16: Adapters and Recyclers
    1. Technical requirements
    2. RecyclerView and RecyclerAdapter
    3. The problem with displaying lots of widgets
    4. The solution to the problem of displaying lots of widgets
    5. How to use RecyclerView and RecyclerAdapter
    6. What we will do to set up RecyclerView with RecyclerAdapter and an ArrayList of notes
    7. Adding RecyclerView, RecyclerAdapter, and ArrayList to the Note to Self project
    8. Removing the temporary "Show Note" button and adding RecyclerView
    9. Creating a list item for RecyclerView
    10. Coding the RecyclerAdapter class
    11. Coding MainActivity to use the RecyclerView and RecyclerAdapter classes
    12. Running the app
    13. Frequently asked questions
    14. Summary
  22. Chapter 17: Data Persistence and Sharing
    1. Technical requirements
    2. Android intents
    3. Switching Activity
    4. Passing data between activities
    5. Adding a settings page to Note to Self
    6. Creating SettingsActivity
    7. Designing the settings screen layout
    8. Enabling the user to switch to the settings screen
    9. Persisting data with SharedPreferences
    10. Reloading data with SharedPreferences
    11. Making the Note to Self settings persist
    12. Coding the SettingsActivity class
    13. Coding the MainActivity class
    14. More advanced persistence
    15. What is JSON?
    16. Java exceptions – try, catch, and finally
    17. Backing up user data in Note to Self
    18. Frequently asked questions
    19. Summary
  23. Chapter 18: Localization
    1. Technical requirements
    2. Making the Note to Self app accessible for Spanish and German speakers
    3. Adding Spanish language support
    4. Adding German language support
    5. Adding the string resources
    6. Running Note to Self in German or Spanish
    7. Making the translations work in Java code
    8. Summary
  24. Chapter 19: Animations and Interpolations
    1. Technical requirements
    2. Animations in Android
    3. Designing cool animations in XML
    4. Instantiating animations and controlling them with Java code
    5. More animation features
    6. Animation demo app – introducing SeekBar
    7. Laying out the animation demo
    8. Coding the XML animations
    9. Wiring up the animation demo app with Java
    10. Frequently asked questions
    11. Summary
  25. Chapter 20: Drawing Graphics
    1. Technical requirements
    2. Understanding the Canvas class
    3. Getting started drawing with Bitmap, Canvas, and ImageView
    4. Using the Canvas class
    5. Preparing the instances of the required classes
    6. Initializing the objects
    7. Setting the Activity content
    8. Canvas demo app
    9. Creating a new project
    10. The Android coordinate system
    11. Plotting and drawing
    12. Creating bitmaps
    13. Manipulating bitmaps
    14. What is a bitmap exactly?
    15. The Matrix class
    16. Bitmap manipulation demo app
    17. Adding the graphic to the project
    18. Frequently asked question
    19. Summary
  26. Chapter 21: Threads and Starting the Live Drawing App
    1. Technical requirements
    2. Creating the Live Drawing project
    3. Refactoring MainActivity to LiveDrawingActivity
    4. Locking the game to fullscreen and landscape orientation
    5. Looking ahead at the Live Drawing app
    6. Coding the LiveDrawingActivity class
    7. Coding the LiveDrawingView class
    8. Coding the LiveDrawingView class
    9. The game loop
    10. Threads
    11. Problems with threads
    12. Implementing the game loop with a thread
    13. Implementing Runnable and providing the run method
    14. Coding the thread
    15. Starting and stopping the thread
    16. Using the Activity lifecycle to start and stop the thread
    17. Coding the run method
    18. Running the app
    19. Summary
  27. Chapter 22: Particle Systems and Handling Screen Touches
    1. Technical requirements
    2. Adding custom buttons to the screen
    3. Implementing a particle system effect
    4. Coding the Particle class
    5. Coding the ParticleSystem class
    6. Spawning particle systems in the LiveDrawingView class
    7. Handling touches
    8. Coding the onTouchEvent method
    9. Finishing the HUD
    10. Running the app
    11. The Android Studio Profiler tool
    12. Summary
  28. Chapter 23: Supporting Different Versions of Android, Sound Effects, and Spinner Widget
    1. Handling different versions of Android
    2. Detecting the current Android version
    3. The SoundPool class
    4. Initializing SoundPool the new way
    5. Initializing SoundPool the old way
    6. Sound demo app introducing the Spinner widget
    7. Making sound effects
    8. Laying out the sound demo
    9. Coding the sound demo
    10. Summary
  29. Chapter 24: Design Patterns, Multiple Layouts, and Fragments
    1. Technical requirements
    2. Introducing the model-view-controller pattern
    3. Android design guidelines
    4. Real-world apps
    5. Device detection mini-app
    6. Coding the MainActivity class
    7. Running the app
    8. Configuration qualifiers
    9. The limitation of configuration qualifiers
    10. Fragments
    11. Fragments have a lifecycle too
    12. Managing Fragments with FragmentManager
    13. Our first Fragment app
    14. Fragment reality check
    15. Frequently asked question
    16. Summary
  30. Chapter 25: Building a Simple Image Gallery App
    1. Technical requirements
    2. Angry Birds classic swipe menu
    3. Building an image gallery/slider app
    4. Implementing the layout
    5. Coding the PagerAdapter class
    6. Coding the MainActivity class
    7. Running the gallery app
    8. Summary
  31. Chapter 26: Advanced UI with Navigation Drawer and Fragment
    1. Technical requirements
    2. Introducing NavigationView
    3. Examining the Simple Database app
    4. Insert
    5. Delete
    6. Search
    7. Results
    8. Starting the Simple Database project
    9. Exploring the autogenerated code and assets
    10. Coding the Fragment classes and their layouts
    11. Creating the empty files for the classes and layouts
    12. Coding the classes
    13. Designing the layouts
    14. Designing content_insert.xml
    15. Designing content_delete.xml
    16. Designing content_search.xml
    17. Designing content_results.xml
    18. Using the Fragment classes and their layouts
    19. Editing the Navigation Drawer menu
    20. Adding a holder to the main layout
    21. Coding the MainActivity.java class
    22. Summary
  32. Chapter 27: Android Databases
    1. Technical requirements
    2. Databases 101
    3. What is a database?
    4. What is SQL?
    5. What is SQLite?
    6. SQL syntax primer
    7. SQLite example code
    8. Android SQLite API
    9. SQLiteOpenHelper and SQLiteDatabase
    10. Building and executing queries
    11. Database cursors
    12. Coding the database class
    13. Coding the Fragment classes to use the DataManager class
    14. Running the Age Database app
    15. Summary
  33. Chapter 28: A Quick Chat before You Go
    1. Publishing
    2. Make an app!
    3. Keep learning
    4. Keep reading
    5. GitHub
    6. Stack Overflow
    7. Android user forums
    8. Higher-level study
    9. My other channels
    10. Goodbye and thank you
    11. Why subscribe?
  34. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
3.141.35.60