You are on page 1of 27

UNIVERSITATEA TEHNICĂ “GH.

ASACHI” DIN IAŞI


FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Intro in Android

2021
Intro in Android
Contents
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

1. What is Android

2. Android Studio
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

3. Programming languages

4. Android Arhitecture

5. Gradle

6. Android devices types

7. Creating the first app


Intro in Android
What is Android?
❖Android is an Operating System for mobile devices developed by Google, which is built
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

upon Linux kernel.

❖It was first developed by Android Inc, a company located in California, USA, which
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

was bought by Google in 2005.

❖Android is an open source OS and a free development platform for developers.

❖The first phone with Android OS was HTC Dream, launched in 2008.

❖Since 2008, Android has been developed into several versions. Their code names were

in alphabetical order and each name was representing a cake. For example, 4.4 was

named KitKat, 7.0 was named Nougat, 9.0 was named Pie. From version 10, which was

launched in September 2019, Google started to name the versions just with numbers

❖The current version is Android 12, launched on October 2021.


Intro in Android
Android Studio
❖ Android Studio is the official IDE(Integrated Development Environment) provided by
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Google for developing Android Applications, available for free, based on Intellij Idea, an

IDE designed for developing Java applications.


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖The first stable version of Android Studio was launched in December 2014 and has

replaced Eclipse (with Android Development Tools(ADT)) as the primary IDE for Android

development.

❖Android Studio offers full support for developing Android applications, which includes

the possibility to debug and run the applications on an Android Virtual Device(AVD) or

on a real device.
Intro in Android
Programming languages
❖The main programming language for developing Android Applications is Java. Android
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

provides comprehensive Application Programming Interfaces(APIs) which allow

developers to create Applications and to access functionalities provided by the Android.


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖Which each Android version release, a new API version is released too and becomes

part of Android SDK(Software Developer Kit)

❖Java code is run by a virtual machine called Android Runtime(ART), which replaced

Dalvik.

❖Another support programming language is C/C++. The low-level layers, for example

Hardware Abstraction Layer(HAL), are developed in C/C++. Applications can also

include C++ code, by using JNI.

❖Since 2017, Kotlin programming language is also supported.


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Android Architecture
Intro in Android

Source of photo:
https://developer.android.com/guide/platform
Intro in Android
Gradle
❖ The tool used by Android Studio to build an Android Project is Gradle.
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

❖ Gradle is a specialized tool for building applications and projects, independent to the

chosen programming language. Its official site is https://gradle.org/


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖ The build with Gradle can be launched from Android Studio menu or from console.
Intro in Android
Android Device Types
❖ Android applications extended from Smartphones and Tablets to:
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

– Watches, with Wear OS

– TVs, with Android TV


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

– Cars, with Android Auto and Android Automotive

– Android Things

– Even personal computers, with some custom Android versions


Intro in Android
Building An “Empty Activity” project
❖ In order to create a new project, the following steps need to be performed:
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

– From File menu, select New Project

– In “Phone and Tablet” tab, select “Empty Activity” and click Next
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

• Enter a name for the application. For example: IntroAndroid

• One can edit the Package name

• Edit the Save location, if necessary

• Select Java as language

• Select the default API version

• Click Finish
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Project structure
❖ Structure of the Empty Activity project:
Intro in Android
Intro in Android
Project structure>MainActivity
❖ An activity represents one screen of the application’s user interface. When an “Empty
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Activity” project is created, Android Studio creates a default activity class, named
MainActivity, and an xml, named activity_main.xml, that describes the content of
the user interface(the layout) of that activity.
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

MainActivity.java

activity_main.xml
Intro in Android
Project structure>AndroidManifest.xml
❖ In app>manifests>AndroidManifest.xml, in tag <activity>, it is specified the Activity
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

class that is loaded when the application starts.


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI
Intro in Android
Project structure>activity_main.xml
❖ The user interface(the layout) is defined in an xml. Each graphical element of the
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

interface(ex. button, input text) is identified by a tag, which has several attributes, like
id, name, text, width, height, etc.
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

A TextView(label)
with with text
“Hello World!”
Intro in Android
Building an application
❖ In order to build(compile) an application, one can select menu Build->Make Project or
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Rebuild Project, or the Build Icon. The result is displayed in the Build Output Window
Build Icon Build Menu
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

Build Window
Intro in Android
Running an application
❖ An application can be run in two environments:
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

– On an emulator device chosen from Android Virtual Device(AVD) Manager

– On a real device
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI
Intro in Android
Adding a virtual device AVD Manager
❖ Android Virtual Device(AVD) Manager can be accessed from Tools->AVD Manager
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

❖ From AVD Manager, in order to add a new Virtual device, one can select “Create

Virtual Device” and to pick the desired device:


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI
Intro in Android
SDK Manager
❖ One the next step, it shall be selected the Android version(the SDK) that will be
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

installed on the AVD.


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖The installed SDKs are visible in Tools>”SDK Manager”


Intro in Android
Enabling testing on a real device
❖ In order to run the app on a real device, the USB debugging shall be enabled on the
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

phone. USB debugging can be turned On from “Settings”>“Developer options” menu,

which is a hidden menu, by default.


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

In order to enable it, go to Settings>About phone and tap “Build number” seven

times.

❖Turn On also Stay Awake, in order to keep the screen On while testing the

application.

❖ After USB debugging is enabled, the next step is to connect the phone to the

computer with an USB cable.

❖When the phone is connected, the real device should be available in the Run menu

❖Selecting the real device will start the application on the real device.
Intro in Android
Running the app
❖ The device on which the application shall run can be selected from the device list. In
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

the above picture are listed Pixel XL(an AVD) and a Samsung phone, which was

connected on the USB.


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖In order to run the application, the green triangle button shall be selected or to select

Run>Run menu.
Intro in Android
Editing User Interface
❖The user interfaces are defined in the layout folder, as xml files. The xmls can be
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

edited directly, in Code view, or by a graphical interface, in Design view. Switch between XML
view, Design View or
Design Area Split View
Area to edit the xml
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI
Intro in Android
Editing User Interface>Design View
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Different UI elements Enabling the view of different Layout view The attributes of the
that can be added to elements(Constraints, selected UI element
the layout Margins)
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI
Intro in Android
Example: Adding UI elements and drawing constraints
❖Delete the “Hello World” TextView, that was by default added by Android Studio.
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

❖From Palette, drag and drop a TextView to the layout.

❖ Select it and from Attributes area:


UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖ change the id to textViewEmail. The id uniquely identifies an UI element

❖ change the name to Email

❖ Add constraints by dragging lines from the bullets of each of the sides of the
The four constraints
TextView to the sides of the layout that define how the
element is placed
relative to the other
elements(the layout, in
this case)

❖Adjust the position of the element in the layout:


Intro in Android
Editing the User Interface from the layout xml
❖The UI can be edited from the layout xml too.
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

❖Example: Go to Split View and in activity_main.xml change the “android:text” attribute

to “Email Address”
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖Change the width or the height attributes accordingly, in case the new text doesn’t fit

properly.
Intro in Android
Exercise>Adding UI elements
❖ Add a PlainText to the right of the textViewEmail added previously:
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

- Set the id to editTextTextEmail and delete the text.

- Draw the four constraints. The left constraint shall be linked to textViewEmail
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

element, while the other to the top, bottom and right sides of the layout
Intro in Android
Exercise>Adding UI elements
❖ Add a Button below the textViewEmail:
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

- Set the id to buttonSubmit and set the text Submit.

- Draw the four constraints. The top constraint shall be linked to textViewEmail
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

element, while the other to the left, bottom and right sides of the layout
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

Exercise>Adding UI elements
❖Run the application on an AVD or on a real device
Intro in Android
Intro in Android
Bibliography
❖ “Hello, Android”, Ed Burnette, 2015
FACULTATEA DE ELECTRONICĂ, TELECOMUNICAŢII ŞI TEHNOLOGIA INFORMAŢIEI

❖ “Android Studio Cookbook”, Mike van Drongelen, 2017

❖https://developer.android.com/guide/platform
UNIVERSITATEA TEHNICĂ “GH. ASACHI” DIN IAŞI

❖https://www.vogella.com/tutorials/android.html

You might also like