Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android Programming for Beginners

You're reading from   Android Programming for Beginners Learn all the Java and Android skills you need to start making powerful mobile applications

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher Packt
ISBN-13 9781785883262
Length 698 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Paresh Mayani Paresh Mayani
Author Profile Icon Paresh Mayani
Paresh Mayani
John Horton John Horton
Author Profile Icon John Horton
John Horton
Arrow right icon
View More author details
Toc

Table of Contents (32) Chapters Close

Preface 1. The First App FREE CHAPTER 2. Java – First Contact 3. Exploring Android Studio 4. Designing Layouts 5. Real-World Layouts 6. The Life and Times of an Android App 7. Coding in Java Part 1 – Variables, Decisions, and Loops 8. Coding in Java Part 2 – Methods 9. Object-Oriented Programming 10. Everything's a Class 11. Widget Mania 12. Having a Dialogue with the User 13. Handling and Displaying Arrays of Data 14. Handling and Displaying Notes in Note To Self 15. Android Intent and Persistence 16. UI Animations 17. Sound FX and Supporting Different Versions of Android 18. Design Patterns, Fragments, and the Real World 19. Using Multiple Fragments 20. Paging and Swiping 21. Navigation Drawer and Where It's Snap 22. Capturing Images 23. Using SQLite Databases in Our Apps 24. Adding a Database to Where It's Snap 25. Integrating Google Maps and GPS Locations 26. Upgrading SQLite – Adding Locations and Maps 27. Going Local – Hola! 28. Threads, Touches, Drawing, and a Simple Game 29. Publishing Apps 30. Before You Go Index

What makes an Android app

We already know that we will write Java code that will itself use other people's Java code and will be compiled into DEX code that runs on the DVM. In addition to this, we will also be adding and editing other files as well. These files are known as Android resources.

Android resources

Our app will include resources such as images, sounds, and user interface layouts that are kept in separate files from the Java code. We will slowly introduce ourselves to them over the course of this book.

They will also include files that contain the textual content of our app. It is a convention to refer to the text in our app through separate files because it makes them easy to change, and this makes it easy to create apps that work for multiple different languages.

Furthermore, the actual UI layouts of our apps, despite the option to implement them with a visual designer, are actually read from text-based files by Android.

Android (or any computer), of course, cannot read and recognize text in the same way that a human can. Therefore, we must present our resources in a highly organized and predefined manner. To do so, we will use Extensible Markup Language (XML). XML is a huge topic but, fortunately, its whole purpose is to be both human and machine readable. We do not need to learn this language, we just need to observe (and then conform to) a few rules. Furthermore, most of the time when we interact with XML, we will do so through a neat visual editor provided by Android Studio. We can tell when we are dealing with an XML resource because the filename will end with the .xml extension.

You do not need to memorize this, as we will constantly be returning to this concept throughout the book.

The structure of Android's Java code

In addition to these resources, it is worth noting that Java, as used in Android, has a structure to its code. There are many millions of lines of code that we can take advantage of. This code will obviously need to be organized in a way that makes it easy to find and refer to. It is organized under predefined packages that are specific to Android.

Android packages

Whenever we create a new Android app, we will choose a unique name known as a package. We will see how to do this in the Our first Android app section. Packages are often separated into subpackages, so they can be grouped together with other similar packages. We can simply think of these as folders and subfolders.

We can also think of all the packages that the Android API makes available to us as books that contain code, from a library. Some common Android packages we will use include the following:

  • android.graphics
  • android.database
  • android.view.animation

As you can see, they are arranged and named to make what is contained in them as obvious as possible.

Tip

If you want to get an idea for the sheer depth and breadth of the Android API, then take a look at the Android package index at http://developer.android.com/reference/packages.html.

Earlier, we learned that reusable code blueprints that we can transform into objects are called classes. Classes are contained in these packages. We will see in our very first app how to easily import other people's packages along with specific classes from those packages for use in our projects. A class will almost always be contained in its own file, with the same name as the class, and have the .java file extension.

In Java, we further break up our classes into sections that perform the different actions for our class. We call these sections methods. These are, most often, the methods of the class that we will use to access the functionality provided within all those millions of lines of code. We do not need to read the code. We just need to know which class does what we need, which package it is in, and which methods from within the class give us precisely the results we are after.

The next diagram shows a representation of the Android API. We can think about the structure of the code that we will write in exactly the same way, although we will most likely have just one package per app. Of course, because of the object-oriented nature of Java, we will only be using selective parts from this API. Also note that each class has its own distinct data. Typically, if you want access to the data in a class, you need to have an object of that class.

Android packages

You do not need to memorize this, as we will constantly be returning to this concept throughout the book.

By the end of this chapter, we will have imported multiple packages and some classes from them and we will have used other people's methods. By the end of Chapter 2, Java – First Contact, we will have even written our very own methods as well.

You have been reading a chapter from
Android Programming for Beginners
Published in: Dec 2015
Publisher: Packt
ISBN-13: 9781785883262
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime