Android Programming for Beginners - Third Edition

Android Programming for Beginners - Third Edition

Read it now on the O’Reilly learning platform with a 10-day free trial.

O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Book description

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

Key Features

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

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.

Show and hide more Table of contents Product information

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
    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
      1. Understanding the Android API
      2. Java is object-oriented
      3. Run that by me again – what exactly is Android?
      4. Android Studio
      1. Android resources
      1. Packages
      2. Classes
      3. Methods
      1. Running and debugging the app on an Android emulator
      2. Running the app on a real device
      1. Technical requirements
      2. Examining the logcat output
        1. Filtering the logcat output
        1. Examining the MainActivity.java file
        2. Examining the app layout file
        1. Adding a button via the visual designer
        2. Adding a button by editing the XML code
        3. Giving the buttons unique id attributes
        4. Positioning the two buttons in the layout
        5. Making the buttons call different methods
        1. Adding message code to the onCreate method
        2. Writing our own Java methods
        1. Technical requirements
        2. Project Explorer and project anatomy
        3. Exploring the file and folder structure of the Empty Activity project template
          1. Exploring an Empty Activity project
          1. Emulator control panel
          2. Using the emulator as a real device
          1. Technical requirements
          2. Finding out about Material Design
          3. Exploring Android UI design
          4. Introducing layouts
            1. Creating and exploring a layout project
            2. Building a layout with LinearLayout
            3. Adding a LinearLayout layout type to a project
            4. Preparing your workspace
            5. Examining the generated XML
            6. Adding a TextView to the UI
            7. Wiring up the UI with the Java code (Part 1)
            8. Adding layouts within layouts
            9. Making the layout look pretty
            10. Wiring up the UI with Java code (Part 2)
            1. Adding a CalendarView
            2. Adding and constraining more UI elements
            3. Making the text clickable
            1. Adding a TableRow element to TableLayout
            2. Organizing the table columns
            1. Technical requirements
            2. Attributes quick summary
              1. Sizing using dp
              2. Sizing fonts using sp
              3. Determining size with wrap or match
              4. Using padding and margin
              5. Using the layout_weight property
              6. Using gravity
              1. Setting the view with Java code
              2. Adding image resources
              3. Creating the contents for the cards
              4. Defining dimensions for CardView
              5. Adding CardView to our layout
              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
                1. The lifecycle phases demystified
                1. Coding the lifecycle demo app
                2. Running the lifecycle demo app
                3. Examining the lifecycle demo app output
                4. Some other overridden methods
                1. Technical requirements
                2. Java is everywhere
                3. Understanding Java syntax and jargon
                  1. More code comments
                  1. Types of variables
                  1. Variable declaration
                  2. Variable initialization
                  1. The assignment operator
                  2. The addition operator
                  3. The subtraction operator
                  4. The division operator
                  5. The multiplication operator
                  6. The increment operator
                  7. The decrement operator
                  1. Expressing Yourself demo app
                  1. Technical requirements
                  2. Making decisions in Java
                    1. Indenting code for clarity
                    2. More operators
                    3. How to use all these operators to test variables
                    1. The switch demo app
                    1. while loops
                    2. do while loops
                    1. Technical requirements
                    2. Methods revisited
                      1. What exactly are Java methods?
                      1. Modifier
                      2. Return type
                      3. Name of the method
                      4. Parameters
                      5. The body
                      1. Real-world methods
                      1. Technical requirements
                      2. Important memory management warning
                      3. Object-oriented programming
                        1. What is OOP exactly?
                        2. Why do it like this?
                        3. Class recap
                        1. Class implementation
                        2. Declaring, initializing, and using an object of the class
                        1. More things we can do with our first class
                        1. Technical requirements
                        2. Remember that encapsulation thing?
                          1. Controlling class use with access modifiers
                          2. Controlling variable use with access modifiers
                          3. Methods can have access modifiers too
                          4. Accessing private variables with getters and setters
                          5. Setting up our objects with constructors
                          1. Abstract classes
                          2. Interfaces
                          1. Technical requirements
                          2. All the Android UI elements are classes too
                            1. Re-introducing references
                            2. So how does this heap thing help me?
                            3. Using buttons and TextView widgets from our layout
                            4. Running the app
                            1. Technical requirements
                            2. Declaring and initializing the objects
                            3. Creating UI widgets from pure Java without XML
                            4. Exploring the palette – part 1
                              1. The EditText widget
                              2. The ImageView widget
                              3. Radio buttons and groups
                              1. Switch
                              2. CheckBox
                              3. TextClock
                              4. Using WebView
                              1. Setting up the Widget Exploration project and UI
                              2. Coding the Widget Exploration app
                              1. Technical requirements
                              2. Dialog windows
                                1. Creating the Dialog Demo project
                                2. Coding a DialogFragment class
                                3. Using the DialogFragment class
                                1. Using naming conventions and string resources
                                2. How to get the code files for the Note to Self app
                                3. The completed app
                                4. Building the project
                                5. Preparing the string resources
                                6. Coding the Note class
                                7. Implementing the dialog designs
                                8. Coding the dialog boxes
                                9. Showing our new dialogs
                                1. Technical requirements
                                2. A random diversion
                                3. Handling large amounts of data with arrays
                                  1. Arrays are objects
                                  1. Dynamic array example
                                  1. Multidimensional array mini-app
                                  2. Array-out-of-bounds exceptions
                                  1. The enhanced for loop
                                  1. Technical requirements
                                  2. RecyclerView and RecyclerAdapter
                                    1. The problem with displaying lots of widgets
                                    2. The solution to the problem of displaying lots of widgets
                                    3. How to use RecyclerView and RecyclerAdapter
                                    4. What we will do to set up RecyclerView with RecyclerAdapter and an ArrayList of notes
                                    1. Removing the temporary "Show Note" button and adding RecyclerView
                                    2. Creating a list item for RecyclerView
                                    3. Coding the RecyclerAdapter class
                                    4. Coding MainActivity to use the RecyclerView and RecyclerAdapter classes
                                    1. Technical requirements
                                    2. Android intents
                                      1. Switching Activity
                                      2. Passing data between activities
                                      1. Creating SettingsActivity
                                      2. Designing the settings screen layout
                                      3. Enabling the user to switch to the settings screen
                                      1. Coding the SettingsActivity class
                                      2. Coding the MainActivity class
                                      1. What is JSON?
                                      2. Java exceptions – try, catch, and finally
                                      1. Technical requirements
                                      2. Making the Note to Self app accessible for Spanish and German speakers
                                        1. Adding Spanish language support
                                        2. Adding German language support
                                        3. Adding the string resources
                                        1. Making the translations work in Java code
                                        1. Technical requirements
                                        2. Animations in Android
                                          1. Designing cool animations in XML
                                          2. Instantiating animations and controlling them with Java code
                                          3. More animation features
                                          1. Laying out the animation demo
                                          2. Coding the XML animations
                                          3. Wiring up the animation demo app with Java
                                          1. Technical requirements
                                          2. Understanding the Canvas class
                                            1. Getting started drawing with Bitmap, Canvas, and ImageView
                                            1. Preparing the instances of the required classes
                                            2. Initializing the objects
                                            3. Setting the Activity content
                                            1. Creating a new project
                                            1. Plotting and drawing
                                            1. What is a bitmap exactly?
                                            2. The Matrix class
                                            1. Adding the graphic to the project
                                            1. Technical requirements
                                            2. Creating the Live Drawing project
                                              1. Refactoring MainActivity to LiveDrawingActivity
                                              2. Locking the game to fullscreen and landscape orientation
                                              3. Looking ahead at the Live Drawing app
                                              4. Coding the LiveDrawingActivity class
                                              5. Coding the LiveDrawingView class
                                              6. Coding the LiveDrawingView class
                                              1. Problems with threads
                                              1. Implementing Runnable and providing the run method
                                              2. Coding the thread
                                              3. Starting and stopping the thread
                                              4. Using the Activity lifecycle to start and stop the thread
                                              5. Coding the run method
                                              1. Technical requirements
                                              2. Adding custom buttons to the screen
                                              3. Implementing a particle system effect
                                                1. Coding the Particle class
                                                2. Coding the ParticleSystem class
                                                3. Spawning particle systems in the LiveDrawingView class
                                                1. Coding the onTouchEvent method
                                                2. Finishing the HUD
                                                1. Handling different versions of Android
                                                  1. Detecting the current Android version
                                                  1. Initializing SoundPool the new way
                                                  2. Initializing SoundPool the old way
                                                  1. Making sound effects
                                                  2. Laying out the sound demo
                                                  3. Coding the sound demo
                                                  1. Technical requirements
                                                  2. Introducing the model-view-controller pattern
                                                  3. Android design guidelines
                                                  4. Real-world apps
                                                  5. Device detection mini-app
                                                    1. Coding the MainActivity class
                                                    2. Running the app
                                                    1. The limitation of configuration qualifiers
                                                    1. Fragments have a lifecycle too
                                                    2. Managing Fragments with FragmentManager
                                                    1. Technical requirements
                                                    2. Angry Birds classic swipe menu
                                                    3. Building an image gallery/slider app
                                                      1. Implementing the layout
                                                      2. Coding the PagerAdapter class
                                                      3. Coding the MainActivity class
                                                      4. Running the gallery app
                                                      1. Technical requirements
                                                      2. Introducing NavigationView
                                                      3. Examining the Simple Database app
                                                        1. Insert
                                                        2. Delete
                                                        3. Search
                                                        4. Results
                                                        1. Creating the empty files for the classes and layouts
                                                        2. Coding the classes
                                                        3. Designing the layouts
                                                        4. Designing content_insert.xml
                                                        5. Designing content_delete.xml
                                                        6. Designing content_search.xml
                                                        7. Designing content_results.xml
                                                        1. Editing the Navigation Drawer menu
                                                        2. Adding a holder to the main layout
                                                        3. Coding the MainActivity.java class
                                                        1. Technical requirements
                                                        2. Databases 101
                                                          1. What is a database?
                                                          2. What is SQL?
                                                          3. What is SQLite?
                                                          1. SQLite example code
                                                          1. SQLiteOpenHelper and SQLiteDatabase
                                                          2. Building and executing queries
                                                          3. Database cursors
                                                          1. Publishing
                                                          2. Make an app!
                                                          3. Keep learning
                                                            1. Keep reading
                                                            2. GitHub
                                                            3. Stack Overflow
                                                            4. Android user forums
                                                            5. Higher-level study
                                                            1. Packt is searching for authors like you
                                                            2. Leave a review - let other readers know what you think
                                                            Show and hide more

                                                            Product information

                                                            • Title: Android Programming for Beginners - Third Edition
                                                            • Author(s): John Horton
                                                            • Release date: April 2021
                                                            • Publisher(s): Packt Publishing
                                                            • ISBN: 9781800563438