INSTRUCTOR 1: Welcome to "Getting Started on Android."
This is a crash course in Android development,
and this short video is meant to show you exactly how easy
it is to get started.
Whether this is your 100th startup or your first time
coding, there's something to learn for everyone.
Before you build, you'll have to make important decisions
with your team, like whether to build
an app or a mobile website and the kind of user experience
you want to create.
You should also ask what you want your users
to be able to do with what you build.
Once you've made these decisions,
bring your wireframes along and let's get started.
KATHERINE KUAN: If you haven't installed it yet,
take a moment to do that now using the detailed instructions
provided in the link below.
Open up the Android SDK Manager to see
what tools, platform versions, and components we
have installed.
At the time of this recording, the Android L platform
is available, but it's still in Developer Preview Mode.
That means it's subject to change
until the official release.
And you can't upload your app to Google Play
if it's targeting this L platform version.
Hence we want to use the latest stable platform version.
Deselect all the other packages and just choose
the ones for API Level 19.
We want the SDK, as well as the system images for the emulator.
We also want the Android Support Library
for backwards compatibility.
We picked the latest version of Gingerbread at API Level 10,
because it contains bug fixes that API Level 9 doesn't have.
Then we go ahead and click Next.
We're going to pick the Blank Activity
with Fragment template.
For background context, an activity
serves as a presentation layer for our UI.
And the fragment within it represents
a behavior or portion of the screen.
Now for the moment you've been waiting
for-- let's run the app by clicking on this button.
It will prompt us to choose a device.
Without a physical device, we can
use the emulator, which is included in the Android SDK.
Currently, it says that there are no Android virtual devices
available, so let's open up the AVD Manager to create one.
Then click New.
By creating an AVD, we can configure an emulated device
with the Android platform version
that we want to test on, as well as hardware options.
When it loads up, we see our Sunshine app with the words,
"Hello, world."
And then we'll need to enable USB debugging.
This can be found in Developer Options in the Settings app.
To find the secret menu, go to the Settings app.
Scroll down to About phone.
Then go down to Build number, and tap on that seven times.
Then, when you go back to Settings,
you'll see the Developer Options menu appear.
Now, in Android Studio, you can hit the Play button
to run the app on your device.
In the Device Chooser dialog, you
should see your connected device.
To prevent the dialog from popping up
in future times, check this box.
Then hit OK to continue.
Within a few moments, you should see it on your phone.
IZABEL GREY: In design, we have a technique.
It's called wireframing, or low-res wireframing.
Imagine there's a task that your user wants to complete.
So for this example, it's-- I'm hungry for cookies.
I want to get some and eat the cookies, basically.
So then you think about, what steps
does your user need to go through to complete this task?
So this is an easy example, because we only have one task.
So the steps would be sign in, decide which cookies you want,
pay for your cookies, and then eat the cookies.
So when we write out each of these steps
at a high level like this, each of these steps
is kind of like a Java interface.
NAZMUL IDRIS: Exactly.
When you think about a Java interface,
it's something that doesn't have any implementation.
So you're not really thinking about the low-level details.
But you're thinking about the contract
that interface has with other interfaces and classes--
which, in this case, if you look at the steps,
it's how these steps connect with each other.
So instead of focusing on just one step and nothing else,
you're really thinking about the big picture.
KATHERINE KUAN: This has the correct flow
for how the user will interact with the app,
but it doesn't have the final visual look and feel yet.
We'll build this up step by step,
starting with the Main Activity.
Then we'll move onto the Detail Activity,
and then later, build up the tablet UI.
INSTRUCTOR 2: MainActivity is launched
when you start the app.
At the bottom of Main Activity, we have PlaceholderFragment.
PlaceholderFragment.
was generated by the template we used when creating our project.
A fragment is a modular container within your activity.
In later lessons, we'll look at how
to use multiple fragments in a single activity.
And we'll actually explain why we're using them at all.
But for now, our activity contains just this one
fragment.
So here, in PlaceholderFragment, is
where we reference our UI layout resource, called fragment_main.
This XML file lives in the resources, res, directory
of our project folder.
You can see other kinds of resources here besides layouts,
such as design assets, or drawables, or strings.
When our activity runs, it creates
this PlaceholderFragment, which then inflates the XML layout
resource, converting everything in the XML file
to a hierarchy of view objects in memory.
By holding Control or Command, depending on your operating
system, and clicking on this reference to fragment_main,
Android Studio will drop us right into the Visual Layout
Editor.
Once we're inside a layout XML file,
we can switch between the Design tab, where we can drag and drop
new UI elements and modify the layout visually,
and the Text tab, where we can see and edit
the XML that defines the layout and UI elements.
KATHERINE KUAN: In order to build a UI in Android,
we use views.
View are rectangles on the screen,
and we may or may not see the borders of that rectangle.
Essentially, a view handles drawing and event handling,
and all the basic widgets in Android
extend from this base class.
The Android Design Guide has visual examples
of these basic building blocks of apps.
INSTRUCTOR 2: Imagine spending hours
crafting the perfect layout.
What happens to that layout when you rotate the device
into a landscape orientation?
Or when it's run on a device with a much larger screen?
The good news is that Android provides
excellent tools to help you with layouts.
You'll want to understand them to make your app look
amazing across the wide variety of phones, tablets,
and other devices you'll want your app to work on.
Today, the lines between phones and tablets are disappearing,
so it's important to think about how your UI will
scale in our multi-screen world.
Don't be overwhelmed.
Just like designing responsive layouts for the web,
build your layouts to be reasonably flexible,
or within a common device size.
Then you can set breakpoints, providing alternative layouts
for those various sizes.
RETO MEIER: All externalized Android resources, everything
from strings, to layouts, to drawables and animations,
are all stored within your project's res folder.
You've already been putting your strings in the strings.xml file
stored in the values folder, and you've
been putting your layouts into the layout folder.
And you know to reference your resources
using @ notation within both your XML or within the code.
And then at run time, Android will
insert the appropriate resource for you.
So far, so good.
And here's where things get a little more interesting.
Android allows you to create alternative versions
of every resource by placing them
into folders with different qualifiers.
We separate each of those using a hyphen.
And we can add those qualifiers based on anything,
from language and/or dialect to whether the device is docked,
the type of touchscreen, the pixel density of the display,
the orientation of the screen, and most importantly
for a responsive design in particular, the smallest
available screen with which you can support that layout.
INSTRUCTOR 1: This was a lightweight introduction
to Android development.
You can learn more by checking out our full Udacity
course to get the full content, or by visiting the Android
developer site.
If you're ready to distribute and monetize,
you should check out our great resources,
including quality guidelines and go-to-market processes
for startups at g.co/launch.
All the best, and happy coding.