Week 3
Lecture dates: April 10th and 12th
Last updated
Lecture dates: April 10th and 12th
Last updated
In this week, we will cover one of the fundamental topics in Android development - the Activity Lifecycle. We also gain exposure logging with commands like log
and logcat
. We will also familiarize ourselves with Toasts
messages and how notification works.
We will end the week by understanding how to read and use XML
to define our user interface layouts.
An activity represents a screen that the user sees. Sometimes people refer to each screen as the presentation layer.
Here's the actual definition from the official document: "An activity is a single, focused thing that the user can do."
An app can have multiple screens. That means there can also be multiple activities, and they can be switched and interacted with one another during runtime.
Activities are switched and interacted through what's called the lifecycle. Let's imagine that a user is using your awesome app. He sees a notification from another app and decides to open it. When he's done checking out the other app, he switches back to your app. So how should your app respond to each different event/scenario that takes place?
It is very important that you read this link from the official documentation to understand how each individual methods work.
Big Hint: Your understanding of how each of these methods work and relate to one another will be very useful for successfully completing a homework assignment.
While working on your homework assignments or final project, there will come a point in time where you encounter a bug and are unsure of how to proceed. One of the best and easiest way to detect the source of the problem is to write log messages in your code by utilizing the Log
class.
A very handy time to use log messages is when you want to catch exceptions:
All messages logged to the system can be found in the Logcat window.
A toast displays a simple message as a popup. You can determine how long the popup will continue to display.
The toast we've created above is extremely basic. Read this link to learn more about how to configure a toast to best align with your project' needs.
A dialog differs from a toast because it provides a way to prompt the user to make a decision or enter information. Usually, you'd use a dialog when you want the user to take an action before proceeding.
To create an alert, you must creating and implementing the AlertDialog
object.
Read this section in the Android Documentation website for more information on alerts and how to use them.
You must learn to understand when and how to utilize certain types of layouts. Each layout (a view group) will create a unique look and feel to your application's user interface.
There are many types of layouts to pick from, and here are some of them:
Layouts
Description
Linear Layout
Aligns all children in a single direction -- vertically or horizontally
Relative Layout
Displays child views in a relative position
Table Layout
Groups views into rows and columns
Absolute Layout
You can specify the exact X and Y coordinates for its children.
List View
Displays a list of scrollable items (similar to iOS)
Grid View
Displays items in a 2D grid and can be scrolled.
Each view object may have a unique ID assigned to it:
This allows you to easily locate the object programmatically inside a class:
With Kotlin, you can also effectively reduce many lines of code needed to initialize each findViewById
for each object. Read this blog post for more details about this.
Tutorials Point - Android - UI Layouts
Udacity - Android XML Visualizer
Futurice - Organizing layout XMLs