Book Image

Android Programming for Beginners - Third Edition

By : John Horton
Book Image

Android Programming for Beginners - Third Edition

By: John Horton

Overview of this book

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.
Table of Contents (30 chapters)

Coding messages to the user and the developer

In the introduction to this chapter and in the previous chapter, we talked a bit about using other people's code, specifically via the classes and their methods, of the Android API. We saw that we could do some quite complex things with insignificant amounts of code (such as talk to satellites).

To get us started, we are going to use two different classes from the Android API that allow us to output messages. The first class, Log, allows us to output messages to the Logcat window. The second class, Toast, is not a tasty breakfast treat, but it will produce a toast-shaped pop-up message for our app's user to see.

Here is the code we need to write to send a message to the Logcat window:

Log.i("info","our message here");

Exactly why this works will become clearer in Chapter 10, Object-Oriented Programming, but for now, we just need to know that whatever we put between the two sets of quote marks will be output to the Logcat window. We will see where to write this type of code shortly.

Here is the code we need to write to send a message to the user's screen:

Toast.makeText(this, "our message",      
Toast.LENGTH_SHORT).show();

This is a very convoluted-looking line of code, and exactly how it works, again, will not become clear until Chapter 10, Object-Oriented Programming. The important thing here is that whatever we put between the quote marks will appear in a pop-up message to our users.

Let's put some code, much like we have just seen, into our app for real.