Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Android Application

Development
with Android Studio 2.3
Lecture Set 02

Android Studio and Android Project

Engr. Adnan Ali Memon


Lecturer Computer Systems Engineering, MUET-Jamshoro
Adnan.tahri@gmail.com
Contents
• Android Studio
o Android Studio
o User Interface – Welcome Screen
o User Interface – Main Window o
User Interface – Tool Windows

• Android Project
o Project
o Modules
o Project Files
o Android Project View
o Creating New Android Project
o Import an Existing Project

Android Application Development by Adnan Ali Memon 2


Android Studio

Android Application Development by Adnan Ali Memon 3


Android Studio
• Android Studio is the official Integrated Development Environment
(IDE) for Android app development, based on IntelliJ IDEA.
• Android Studio offers features
as: o Powerful code editor
o Developer tools
o Gradle-based build system
o Fast and rich android emulator
o Unified environment to develop apps for all android
devices o Extensive testing tools and frameworks
o C++ and NDK support

Android Application Development by Adnan Ali Memon 4


User Interface – Welcome Screen
• It is displayed whenever no any project is currently opened.

Android Application Development by Adnan Ali Memon 5


User Interface – Main Window

Android Application Development by Adnan Ali Memon 6


User Interface – Main Window

Android Application Development by Adnan Ali Memon 7


User Interface – Main Window
• When a new project is created or existing one is opened, the Main
Window appears.
• The Main Window is made up of several logical areas as:

1. Title bar 7. Tool windows


2. Menu bar 8. Status bar
3. Toolbar 9. Design Editor
4. Navigation bar 10. Palette
5. Editor window 11. Component tree
6. Tool window bar 12. Properties

Android Application Development by Adnan Ali Memon 8


User Interface – Main Window
• Title bar: Displays the title of android project currently opened and the
resource file currently you are editing.

• Menu bar: Horizontal bar at the top, containing most of the essential
actions of android studio. It organizes the actions in the form of
drop-down lists.

Android Application Development by Adnan Ali Memon 9


User Interface – Main Window
• Toolbar: Contains shortcut to frequently performed actions.

• Navigation bar: Helps you navigate through your project and open files
for editing.

Android Application Development by Adnan Ali Memon 10


User Interface – Main Window
• Editor window: It is where you create and modify code. Depending on
the current file type, the editor can change. For example, when viewing a
layout file, the editor displays the Layout Editor.

Android Application Development by Adnan Ali Memon 11


User Interface – Main Window
• Tool window bar: Runs around the outside of the IDE window and
contains the buttons that allow you to expand or collapse
individual tool windows.

Android Application Development by Adnan Ali Memon 12


User Interface – Main Window
• Status bar: Displays the status of your project and the IDE itself, as well
as any warnings or messages.

Android Application Development by Adnan Ali Memon 13


User Interface – Main Window
• Design editor: Displays your layout in a combination of the Design and
Blueprint views.

• The editor can preview your layout in different Android devices


and versions.

• You can dynamically resize the layout to be sure it works well on


different screen sizes.

Android Application Development by Adnan Ali Memon 14


User Interface – Main Window

Design View Blueprint View

Android Application Development by Adnan Ali Memon 15


User Interface – Main Window
• The buttons in the top row of the design editor allow you to configure
the appearance of your layout in the editor.

Android Application Development by Adnan Ali Memon 16


User Interface – Main Window
1. Design and blueprint: Select how you'd like to view your layout in the editor. The
Design view displays a color preview of your layout, while the Blueprint view shows only
outlines for each view. Or you can view both Design + Blueprint side by side.
2. Screen orientation: Rotate the device between landscape and portrait.
3. Device type and size: Select the device type (phone/tablet, Android TV, or Android
Wear) and screen configuration (size and density).
4. API version: Select the version of Android on which to preview your layout.
5. App theme: Select which UI theme to apply to the preview. Note: This works only
for supported layout styles; thus many themes in this list result in an error.
6. Language: Select the language to show for your UI strings. This list displays only the
languages available in your string resources.
7. Layout Variants: Switch to one of your alternative layouts for this file, or create a
new one.

Android Application Development by Adnan Ali Memon 17


User Interface – Main Window
• Palette: Provides a list of widgets and layouts that you can drag into
your layout in the editor.

Android Application Development by Adnan Ali Memon 18


User Interface – Main Window
• Component tree: Shows the view hierarchy for your layout.

Android Application Development by Adnan Ali Memon 19


User Interface – Main Window
• Properties: Provides property controls for the currently
selected view.

Android Application Development by Adnan Ali Memon 20


User Interface – Tool Windows
• Instead of using preset perspectives, Android Studio
follows your context and automatically brings up
relevant tool windows as you work.
• By default, the most commonly used tool windows
are pinned to the tool window bar at the edges of the
application window.
• To expand or collapse a tool window, click the tool’s
name in the tool window bar.
• Android Studio offers a wide range of window tool
windows, the most commonly used of which are
shown to right.

Android Application Development by Adnan Ali Memon 21


Android Project

Android Application Development by Adnan Ali Memon 22


Project
• A project in Android Studio contains everything that defines your
workspace for an app, from source code and assets, to test code and
build configurations.

• When you start a new project, Android Studio creates the necessary
structure for all your files and makes them visible in the Project window
on the left side of the IDE.

Android Application Development by Adnan Ali Memon 23


Modules
• A module is a collection of source files and build settings that allow you to
divide your project into discrete units of functionality.

• Your project can have one or many modules and one module may
use another module as a dependency.
• Each module can be independently built, tested, and debugged.

• You can add a new module to your project by clicking File > New >
New Module.
• Android Studio offers a few distinct types of module:

Android Application Development by Adnan Ali Memon 24


Modules
• Android app module: Provides a container for your app's source
code, resource files, and app level settings such as the module-level
build file and Android Manifest file. When you create a new project, the
default module name is "app".

• Library module: Provides a container for your reusable code, which you
can use as a dependency in other app modules or import into other
projects. Structurally, a library module is the same as an app module,
but when built, it creates a code archive file instead of an APK, so it can't
be installed on a device.

Android Application Development by Adnan Ali Memon 25


Modules
• Google Cloud module: Provides a container for your Google Cloud
backend code. This module adds the required code and dependencies
for a Java App Engine backend that uses simple HTTP, Cloud Endpoints,
and Cloud Messaging to connect to your app.

Android Application Development by Adnan Ali Memon 26


Project Files
• Android project contains following group of files
in app module:

• manifests: Contains the AndroidManifest.xml file.

• java: Contains the Java source code files, separated


by package names, including JUnit test code.

• res: Contains all non-code resources, such as XML


layouts, UI strings, and bitmap images, divided
into corresponding sub-directories.

Android Application Development by Adnan Ali Memon 27


Android Project View
• To see the actual file structure of the project
including all files hidden from the Android view,
select Project from the dropdown at the top of the
Project window.

• When you select Project view, you can see a lot


more files and directories. The most important of
which are the following:
• build: Contains build outputs.
• libs: Contains private libraries.

Android Application Development by Adnan Ali Memon 28


Android Project View
• src: Contains all code and resource files for the module in the
following subdirectories:
o androidTest: Contains code for instrumentation tests that run on
an Android device.
o main: Contains the "main" sourceset files: the Android code
and resources shared by all build variants.
▪ AndroidManifest.xml: Describes the nature of the application and each of
its components.
▪ java: Contains Java code sources.
▪ jni: Contains native code using the Java Native Interface (JNI).
▪ gen: Contains the Java files generated by Android Studio, such as your R.java file and
interfaces created from AIDL files.

Android Application Development by Adnan Ali Memon 29


Android Project View
▪ res: Contains application resources, such as drawable files, layout files, and UI string.
▪ assets: Contains file that should be compiled into an .apk file as-is.
o test: Contains code for local tests that run on your host JVM.

• build.gradle (module): This defines the module-specific build


configurations.

Android Application Development by Adnan Ali Memon 30


Creating New Android Project
• A project in Android Studio
contains one or more modules
that keep your code organized
into discrete units of functionality.

• Launch Android Studio.

• To create a new project, click


File > New > New Project.

Android Application Development by Adnan Ali Memon 31


Creating New Android Project
• The next window lets
you configure the
name of your app, the
package name, and
the location of your
project.

• Enter the values


for your project
then click Next.

Android Application Development by Adnan Ali Memon 32


Creating New Android Project
• The next window lets
you select the form
factors supported by
your app, such as
phone, tablet, TV, Wear,
and Google Glass.

• For each form factor,


you can also select the
API Level for that app.

Android Application Development by Adnan Ali Memon 33


Creating New Android Project
• The next screen lets
you select an
activity type to add
to your app.
• This screen displays
a different set of
activities for each of
the form factors you
selected earlier.
• Choose an activity type
then click Next.

Android Application Development by Adnan Ali Memon 34


Creating New Android Project
• The next screen
lets you configure
the activity.

• Enter the activity


name, the layout
name, and the activity
title. Then click Finish.

Android Application Development by Adnan Ali Memon 35


Creating New Android Project
• Now you are ready
to develop your app.

• Android Studio creates


the default structure for
your project and opens
the development
environment.

Android Application Development by Adnan Ali Memon 36


Import an Existing Project
• To import an existing project
into Android Studio, proceed as
follows:
• Click File > New > Import
Project.

Android Application Development by Adnan Ali Memon 37


Import an Existing Project
• In the Select Eclipse or Gradle Project to
Import window that appears, navigate to
the root directory of the project you
want to import.
• Click OK.

• Android Studio then opens the project


in a new IDE window.

Android Application Development by Adnan Ali Memon 38

You might also like