Learn all the Java and Android skills you need to start making powerful mobile applications with practical and actionable steps

Key Features
Kick-start your Android programming career, or just have fun publishing apps to the Google Play marketplace
A first-principles introduction to Java, via Android, which means you’ll be able to start building your own applications from scratch
Learn by example and build four real-world apps and dozens of mini-apps throughout the book
Book Description
Are you trying to start a career in programming, but haven’t found the right way in? Do you have a great idea for an app, but don’t know how to make it a reality? Or maybe you’re just frustrated that in order to learn Android, you must know Java. If so, then this book is for you.

This new and expanded second edition of Android Programming for Beginners will be your companion to create Android Pie applications from scratch. We will introduce you to all the fundamental concepts of programming in an Android context, from the basics of Java to working with the Android API. All examples use the up-to-date API classes, and are created from within Android Studio, the official Android development environment that helps supercharge your application development process.

After this crash course, we’ll dive deeper into Android programming and you’ll learn how to create applications with a professional-standard UI through fragments and store your user’s data with SQLite. In addition, you’ll see how to make your apps multilingual, draw to the screen with a finger, and work with graphics, sound, and animations too.

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

What you will learn
Master the fundamentals of coding Java for Android Pie
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
Find out about the design patterns used by professionals to make top-grade applications
Build, deploy, and publish real Android applications to the Google Play marketplace
Who this book is for
This book is for you if you are completely new to Java, Android, or programming and want to make Android applications. This book also acts as a refresher for those who already have experience of using Java on Android to advance their knowledge and make fast progress through the early projects.

Show and hide moreTable of Contents
Android Programming for Beginners – Second Edition
Table of Contents
Android Programming for Beginners – Second Edition
Why subscribe?
About the author
About the reviewers
Packt is Searching for Authors Like You
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
1. Beginning Android and Java
What’s new in the second edition?
Why Java and Android?
The beginner’s first stumbling block
How Java and Android work together
The Android API
Java is object-oriented
Run that by me again – What exactly is Android?
Android Studio
Setting up Android Studio
Final step – for now
What makes an Android app?
Android resources
The structure of Android’s Java code
Our first Android app
Extra step 1
Extra step 2
Deploying the app so far
Running and debugging the app on an Android emulator
Running the app on a real device
Frequently asked questions
2. First Contact – Java, XML, and the UI Designer
Examining the log output
Filtering the logcat output
A note for early adopters of this book
Exploring the project’s Java code and the main layout’s XML code
Examining the HelloWorldActivity.java file
Code folding (hiding) in Android Studio
The package declaration
Importing classes
The class
Methods inside the class
Summary of the Java code so far
Examining the main layout file
UI layout elements
UI text elements
Adding buttons to the main layout file
Adding a button via the visual designer
Editing the button’s attributes
Examining the XML code for the new button
Adding a button by editing the XML code
Giving the buttons unique id attributes
Positioning the two buttons in the layout
Making the buttons call different methods
Leaving comments in our Java code
Coding messages to the user and the developer
Writing our first Java code
Adding message code to the onCreate method
Examining the output
Writing our own Java methods
Examining the output
Frequently asked questions
3. Exploring Android Studio and the Project Structure
A quick guided tour of Android Studio
Project Explorer and project anatomy
The Empty Activity project
Exploring the Empty Activity project
The manifests folder
The java folder
The res folder
The res/drawable folder
The res/layout folder
The res/mipmap
The colors.xml file
The strings.xml file
The styles.xml file
The Basic Activity project
Exploring the Basic Activity project
The MainActivity.java file
The activity_main.xml file
The extra methods in MainActivity.java
The content_main.xml file
Exploring the Android emulator
Emulator control panel
Using the emulator as a real device
Accessing the app drawer
Viewing active apps and switching between apps
4. Getting Started with Layouts and Material Design
Material design
Exploring Android UI design
Creating the Exploring Layouts project
Building a menu with LinearLayout
Adding a LinearLayout to the project
Preparing your workspace
Examining the generated XML
Adding a TextView to the UI
Adding a multi-line TextView to the UI
Wiring up the UI with the Java code (part 1)
Adding layouts within layouts
Making the layout look pretty
Wiring up the UI with the Java code (part 2)
Building a precise UI with ConstraintLayout
Adding a CalenderView
Resizing a view in a ConstraintLayout
Using the Component Tree window
Adding constraints manually
Adding and constraining more UI elements
Making the text clickable
Laying out data with TableLayout
Adding a TableRow to TableLayout
Using the Component Tree when the visual designer won’t do
Organizing the table columns
Linking back to the main menu
5. Beautiful Layouts with CardView and ScrollView
Attributes quick summary
Sizing using dp
Sizing fonts using sp
Determining size with wrap or match
Using padding and margin
Using the layout_weight property
Using Gravity
Building a UI with CardView and ScrollView
Setting the view with Java code
Adding image resources
Creating the content for the cards
Defining dimensions for CardViews
Adding CardViews to our layout
Including layout files inside another layout
Themes and material design
Using the Android Studio theme designer
Creating a tablet emulator
Frequently asked questions
6. The Android Lifecycle
The life and times of an Android app
How Android interacts with our apps
A simplified explanation of the Android lifecycle
The lifecycle phases demystified
How we handle the lifecycle phases
Lifecycle demo app
Coding the lifecycle demo app
Running the lifecycle demo app
Examining the Lifecycle Demo app output
Some other overridden methods
The structure of Java code – revisited
7. Java Variables, Operators, and Expressions
Java is everywhere
Syntax and jargon
More code comments
Storing and using data with variables
Types of variables
Primitive types
Reference types
Using variables
Variable declaration
Variable initialization
Changing values in variables with operators
The assignment operator
The addition operator
The subtraction operator
The division operator
The multiplication operator
The increment operator
The decrement operator
Expressing yourself demo app
8. Java Decisions and Loops
Making decisions in Java
Indenting code for clarity
More operators
The comparison operator
The logical NOT operator
The NOT equal operator
The greater than operator
The less than operator
The greater than or equal to operator
The less than or equal to operator
The logical AND operator
The logical OR operator
How to use all of these operators to test variables
Using the Java if keyword
Else do this instead
Switching to make decisions
Switch Demo app
Repeating code with loops
While loops
Breaking out of a loop
The continue keyword
Do while loops
For loops
Loops demo app
9. Java Methods
Methods revisited
What exactly are Java methods?
Method structure
Return type
Name of a method
The body
Using methods demo apps
Real world methods
Discovering variable scope
Exploring method overloading
Scope and variables revisited
Frequently asked questions
Further reading
10. Object-Oriented programming
Important memory management warning
Object-oriented programming
What is OOP exactly
Why do it like this?
Class recap
Looking at the code for a class
Class implementation
Declaring, initializing, and using an object of the class
Basic classes app
More things that we can do with our first class
Frequently asked questions
11. More Object-Oriented Programming
Remember that encapsulation thing?
Controlling class use with access modifiers
Class access modifiers
Class access in summary
Controlling variable use with access modifiers
Variable access modifiers
Variable access summary
Methods have access modifiers too
Method access modifiers
Method access summary
Accessing private variables with getters and setters
Setting up our objects with constructors
Static methods
Encapsulation and static methods mini-app
OOP and inheritance
Inheritance example app
Abstract classes
Frequently asked questions
12. The Stack, the Heap, and the Garbage Collector
All the Android UI elements are classes too
Re-introducing references
A quick break to throw out the trash
Seven facts about the Stack and the Heap
So how does this Heap thing help me?
Using Buttons and TextView widgets from our layout
The Inner and Anonymous classes
Frequently asked questions
13. Anonymous Classes – Bringing Android Widgets to Life
Declaring and initializing the objects
Creating UI widgets from pure Java without XML
Exploring the palette – part 1
The EditText widget
The ImageView widget
Radio button and group
Anonymous classes
Exploring the palette – Part 2, and more anonymous classes
Widget exploration app
Setting up the widget exploration project and UI
Coding the widget exploration app
Getting a reference to the parts of the UI
Coding the checkboxes
Changing transparency
Changing color
Changing size
Coding the RadioButtons
Using an anonymous class for a regular button
Coding the Switch
Running the Widget Exploration app
Converting layouts to ConstraintLayout
14. Android Dialog Windows
Dialog windows
Creating the Dialog Demo project
Coding a DialogFragment class
Using chaining to configure the DialogFragment
Using the DialogFragment class
The Note to self app
Using naming conventions and String resources
How to get the code files for the Note to self app
The completed app
Building the project
Preparing the String resources
Coding the Note class
Implementing the Dialog designs
Coding the dialog boxes
Coding the DialogNewNote class
Coding the DialogShowNote class
Showing our new dialogs
Coding the floating action button
15. Arrays, ArrayList, Map and Random Numbers
A random diversion
Handling large amounts of data with arrays
Arrays are objects
Simple array example mini-app
Getting dynamic with arrays
Dynamic array example
Entering the nth dimension with Arrays
Multidimensional Array mini app
Array out of bounds exceptions
The enhanced for loop
Arrays and ArrayLists are polymorphic
More Java Collections – Meet Java Hashmap
The Note to Self app
Frequently asked questions
16. Adapters and Recyclers
RecyclerView and RecyclerAdapter
The problem with displaying lots of widgets
The solution to the problem with displaying lots of widgets
How to use RecyclerView and RecyclerAdapter
What we will do to set up RecyclerView with RecyclerAdapter and an ArrayList of notes
Adding RecyclerView, RecyclerAdapter, and ArrayList to the Note to Self project
Removing the temporary Show Note button and adding the RecyclerView
Creating a list item for the RecyclerView
Coding the RecyclerAdapter class
Coding the NoteAdapter constructor
Coding the onCreateViewHolder method
Coding the onBindViewHolder method
Coding getItemCount
Coding the ListItemHolder inner class
Coding MainActivity to use the RecyclerView and RecyclerAdapter classes
Adding code to onCreate
Modifying the addNote method
Coding the showNote method
Running the app
Frequently asked questions
17. Data Persistence and Sharing
Android Intents
Switching Activity
Passing data between Activities
Adding a settings page to Note to Self
Creating the SettingsActivity
Designing the Settings screen layout
Enabling the user to switch to the settings screen
Persisting data with SharedPreferences
Reloading data with SharedPreferences
Making the Note to Self settings persist
Coding the SettingsActivity class
Coding the MainActivity class
More advanced persistence
What is JSON?
Java exceptions – try, catch, and finally
Backing up user data in Note to Self
Frequently asked questions
18. Localization
Making the Note to Self app for Spanish, English, and German speakers
Adding Spanish support
Adding German support
Adding the string resources
Running Note to Self in German or Spanish
Making the translations work in Java code
19. Animations and Interpolations
Animations in Android
Designing cool animations in XML
Fading in and out
Move it, move it
Scaling or stretching
Controlling the duration
Rotate animations
Repeating animations
Combining animation’s properties with Set
Instantiating animations and controlling them with Java code
More animation features
Animation interpolators
Animations Demo App – introducing SeekBar
Laying out the animation demo
Coding the XML Animations
Wiring up the Animation Demo app in Java
Frequently asked questions
20. Drawing Graphics
Understanding the Canvas class
Getting started drawing with Bitmap, Canvas, and ImageView
Canvas and Bitmap
ImageView and Activity
Canvas, Bitmap, Paint, and ImageView – quick summary
Using the Canvas class
Preparing the instances of the required classes
Initializing the objects
Setting the Activity content
The Canvas Demo app
Creating a new project
Coding the Canvas demo app
Exploring the Bitmap initialization
Drawing on the screen
Explaining Color.argb
Android coordinate system
Plotting and drawing
Creating Bitmaps
Manipulating Bitmaps
What is a Bitmap exactly?
The Matrix class
Inverting a bitmap to face the opposite direction
Rotating the bitmap to face up and down
Bitmap manipulation demo app
Add the graphic to the project
Frequently asked question
21. Threads, and Starting the Live Drawing App
Creating the Live Drawing project
Looking ahead at the Live Drawing app
Coding the LiveDrawingActivity class
Coding the LiveDrawingView class
Coding the LiveDrawingView class
Adding the member variables
Coding the LiveDrawingView constructor
Coding the draw method
Adding the printDebuggingText method
Understanding the draw method and the SurfaceView class
The game loop
Problems with threads
Implementing the game loop with a thread
Implementing Runnable and providing the run method
Coding the thread
Starting and stopping the thread
Using the Activity lifecycle to start and stop the thread
Coding the run method
Running the app
22. Particle Systems and Handling Screen Touches
Adding custom buttons to the screen
Implementing a particle system effect
Coding the Particle class
Coding the ParticleSystem class
Spawning particle systems in the LiveDrawingView class
Handling touches
Coding the onTouchEvent method
Finishing the HUD
Running the app
23. Supporting Different Versions of Android, Sound Effects, and the Spinner Widget
Handling different versions of Android
Detecting the current Android version
The Soundpool class
Initializing SoundPool the new way
Initializing SoundPool the old way
Loading sound files into memory
Playing a sound
Stopping a sound
Sound demo app introducing Spinner widget
Making sound FX
Laying out the sound demo
Coding the Sound demo
24. Design Patterns, Multiple Layouts, and Fragments
Introducing the model-view-controller pattern
Android design guidelines
Real-world apps
Device detection mini-app
Coding the MainActivity class
Unlocking the screen orientation
Running the app
Configuration qualifiers
The limitation of configuration qualifiers
Fragments have a lifecycle too
onAttach and onDetach
onStart, onPause, and onStop
Managing Fragments with FragmentManager
Our first Fragment app
Fragment reality check
Frequently asked question
25. Advanced UI with Paging and Swiping
Angry birds classic swipe menu
Building an image gallery/slider app
Implementing the layout
Coding the PagerAdapter class
Coding the MainActivity class
Running the gallery app
Building a Fragment Pager/slider app
Coding the SimpleFragment class
The fragment_layout
Coding the MainActivity class
The activity_main layout
Running the fragment slider app
26. Advanced UI with Navigation Drawer and Fragment
Introducing the NavigationView
Examining the Simple Database app
Starting the Simple Database project
Exploring the auto-generated code and assets
Coding the Fragment classes and their layouts
Creating the empty files for the classes and layouts
Coding the classes
Designing the layouts
Designing content_insert.xml
Designing content_delete.xml
Designing content_search.xml
Designing content_results.xml
Using the Fragment classes and their layouts
Editing the Navigation Drawer menu
Adding a holder to the main layout
Coding the MainActivity.java
27. Android Databases
Database 101
What is a database
What is SQL
What is SQLite
SQL syntax primer
SQLite example code
Creating a table
Inserting data into the database
Retrieving data from the database
Updating the database structure
Android SQLite API
SQLiteOpenHelper and SQLiteDatabase
Building and executing queries
Database cursors
Coding the database class
Coding the Fragment classes to use the DataManager
Running the Age Database app
28. Coding a Snake Game Using Everything We Have Learned So Far
How to play
Getting started with the Snake game
Make the app full screen and landscape
Adding some empty classes
Coding SnakeActivity
Adding the sound effects
Coding the game engine
Coding the members
Coding the constructor
Coding the newGame method
Coding the run method
Coding the updateRequired method
Coding the update method
Coding the draw method
Coding onTouchEvent
Coding pause and resume
Running the game
Adding the graphics
Coding the apple
The Apple constructor
Using the apple
Running the game
29. Enumerations and Finishing the Snake Game
Add the sound to the project
Coding the Snake class
Coding the constructor
Coding the reset method
Coding the move method
Coding the detectDeath method
Coding the checkDinner method
Coding the draw method
Coding the switchHeading method
Using the snake class and finishing the game
Running the completed game
30. A Quick Chat Before You Go
Making an app!
Carrying on learning
Carrying on reading
Android user forums
Higher-level study
My other channels
Goodbye and thank you
Other Books You May Enjoy
Leave a review – let other readers know what you think
Show and hide more

Need Unlimited Access To Movies, TV Series, Music and eBooks? Click Here To Get Help

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top