0% found this document useful (0 votes)
20 views

Android Studio Lab1

The document provides an overview of Android Studio, including how to download it, the differences between mobile websites and mobile apps, Android platforms, Android OS architecture, features of Android Studio, templates, starting a new project, key Android development concepts, and more. It discusses downloading and installing Android Studio, creating virtual devices for testing apps, common Android project structures, activities and their lifecycles, XML and layout files, and other core Android development topics.

Uploaded by

Azmeraw Zenaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Android Studio Lab1

The document provides an overview of Android Studio, including how to download it, the differences between mobile websites and mobile apps, Android platforms, Android OS architecture, features of Android Studio, templates, starting a new project, key Android development concepts, and more. It discusses downloading and installing Android Studio, creating virtual devices for testing apps, common Android project structures, activities and their lifecycles, XML and layout files, and other core Android development topics.

Uploaded by

Azmeraw Zenaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 56

Android Studio

Lab session
Outline
➔ Download
➔ Mobile website vs mobile app
➔ Android platforms
➔ Android OS architecture
➔ Features of Android studio
➔ Templates
➔ Starting a new project
➔ Key android development concepts
Download site
➢ Download Android Studio from https://developers.android.com official
website
Comparison

Mobile website Mobile app

● It is a website for mobile ● App is installed in mobiles


● Requires internet connection to ● Uses mobile resources like
function Location
● For example:- used for content ● Faster
sharing ● Can work without the internet
● Expensive
● Built from scratch
● Needs approval from app store
Android platforms
● Chromebook
○ Used in portable laptops
● Android Tv
○ Is a Tv with a mobile experience
● Android Auto
○ Enables to connect your phone to your car
● WearOS
○ Smartwatches and wearables
Android Languages

Java Kotlin

● Released in 1995 ● Introduced in 2011 by JetBrains


● Used for many types of ● Concise and time saving
development ● Easier maintenance
● Interoperable with java
● Addresses common issues easily
Android OS architecture
● Android OS is a stack of software components roughly divided into 5 sections
○ Applications
○ Applications framework
○ Android runtime
○ Platform Libraries
○ Linux Kernel
Features of Android studio
● Launched in 2013
● Provides complete build system (Gradle)
● Fast emulation
● Different components
○ Toolbar
○ Editor
○ Navigation pane
○ Tool window bar
○ Status bar
● Project templates
Starting a new project
● Follow the following steps
○ New project
○ Phone and tablet
○ Empty activity
○ Next
○ Write name of the project/app
○ Select language (java)
○ Select version of SDK ( with API level )
○ Click Finish
○ Wait until the project loads
Templates
● Android studio comes with pre-built project templates which may help as a starting
file
● Some of the templates are
○ Basic activity template
○ Navigation activity template
○ Empty activity template
● Advantages
○ Clear project structure
○ Preview of platforms
○ Build apps quickly
Key android development
concepts
Top level components
● 4 top level components provide the ability to do everything
○ Activity
■ Can be a single screen of an app
○ Service
■ Works in the background
○ Content provider
■ Responsible to share data
○ Broadcast receiver
■ Responds to messages in real time
Activity components
● It presents the content users interact with on the screen
● Represents something an application can do
● An application can have more than 1 activities
– recent developers follow – single-activity - architecture
Android views
● Views occupy rectangular area on the screen
● Responsible for drawing and event handling
● Can display images , text, etc
● Combination of views forms design interface
Android Layout files
● Each android application layout is represented by an XML file
● The XML file serves as a blueprint for the interface of an application
● Views can also be created using java or kotlin
● Jetpack compose – can also be used to create user interfaces using kotlin code only
XML
● Stands for Extended markup language
● Is used to develop apps user interface
● The whole structure is built on tags
HTML vs XML

HTML XML

● Designed to display data with ● Designed to carry data with focus


focus on how data looks on what data is
● Tags are predefined ● Tags are not predefined
XML syntax
● Xml document must have a root element
<root>
<child>
<subchild> ….. </subchild>
</child>
</root>
XML syntax rules
● All elements must have a closing tag
● Tags are case-sensitive
● Elements must be properly nested
● Attribute values must always be quoted
● Comments are similar to HTML
● White space is preserved in XML
Android Virtual Device ( AVD )Manager
● AVD manager optimizes android apps for different devices
● Helps to test apps
● Lets us create and configure virtual devices
● Running virtual device requires – virtualization tool for hardware acceleration to be
enabled i.e. Hyper-V
○ Windows 10 is preloaded with this feature
● If Hyper-V is not enabled – HAXM hardware acceleration tool will be downloaded
together with an Emulator
AVD configuration
● Emulator performance can be chosen:
○ Cold boot
■ Emulator starts as a first time boot
○ Quick boot
■ Emulator continues boot from last time state
○ Snapshot boot
■ Emulator starts from a saved screenshot state
Emulator
● It is a computer program that imitates real device
● To use it – you need to download it first
● Used for testing our app
● Requires high computing resources
○ Disk space
○ RAM
● Examples
○ Bluestacks
○ Apptize.io
Configuring emulator
● We can configure the following for emulator
○ Device name
○ Startup orientation
○ Set number of processor cores
○ Override the default RAM value
Android Resources
● Lets us manage, change and access our resources globally across our app
● Some of the resources are
○ String
○ Color
○ Themes
○ Dimension
○ Font
Mobile CPU architecture
● To develop and deploy apps for different mobile devices, the cpu architecture must be
considered
● 3 main CPU architectures are used in smartphones
○ ARM - most common and optimized for battery use
○ ARM 64 – supports 64-bit processing – used in newer devices
○ X86 – better embodies mobile first mentality – low power consumption, simple instruction sets etc
Android Studio project structure
● .gradle
○ Contains configurations and files used for project building
○ Auto generated
● .idea
○ Contains metadata of project
● App
○ Contains project source code
● Gradle( androids build system )
○ .gitignore -- specify sensitive files and folders
○ build-gradle -- specify and manage configuration options
○ gradlew -- created whenever a new feature is required
○ local-properties -- local configuration info
○ settings.gradle -- handles settings for projects and modules
Android Studio project structure
● MainActivity
○ Generated when a project is created
○ Activity class contains a layout
○ onCreate() function must be in your activity class to run an android app
Res folder
● Contains the following
○ Drawable
○ Mipmap
○ Layout
○ values
● Both drawable and mipmap store image assets
● Mipmap
○ renders high quality images across different devices
○ It is an upgrade and preferable
○ Images will not become blurry
○ Uses webp images file format ( extension )
Android Manifest
● Used as configuration file to define what an app requires to run
● Helps to define permissions
● e.g sendSMS
<uses-permission android-name=“android.permission.SEND_SMS”>
Layout folder
● Used to manage UI
● Contains the xml files of your app
Dimension
● Defined in XML
● Specified with a number followed by a unit of measure
● Example : 5sp, 15dp, 12px
● The following unit of measure are supported in android
○ dp (density independent pixel) – for margin, padding, etc.
○ sp (space independent pixel) – for font size
○ pt (point)
○ px (pixel)
○ mm (milimmeter)
○ in (inch)
Android densities
● There are a lot of Android devices with different sizes and proportions and each
screen has its density.
● Android densities can be:
○ ldpi (low) ~120dpi
○ mdpi (medium) ~160dpi
○ hdpi (high) ~240dpi
○ xhdpi (extra-high) ~320dpi
○ xxhdpi (extra-extra-high) ~480dpi
○ xxxhdpi (extra-extra-extra-high) ~640dpi
Android densities
● DPI stands for dots per inch.
● Thanks to dp the UI elements look uniform on screens with different densities.
…cont’d
Layouts
● Relative Layouts
○ is a layout which arranges views/widgets/viewGroup according to the position
of other views/widgets/viewGroups i.e the new views are placed relative to the
already existing views
○ Most commonly used layout type
…cont’d
…cont’d
…cont’d
…cont’d
Android Activity Lifecycle – has 7 methods
● onCreate() – Called when the activity is first created
● onStart() – Called just after it’s creation or by restart method after onStop(). Here
Activity start becoming visible to user
● onResume() – Called when Activity is visible to user and user can interact with it
● onPause() – Called when Activity content is not visible because user resume previous
activity
● onStop() – Called when activity is not visible to user because some other activity takes
place of it
● onRestart() – Called when user comes on screen or resume the activity which was
stopped
● onDestroy – Called when Activity is not in background
onCreate()
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

}
onStart(), onRestart()
protected void onStart() {
super.onStart();
}

@Override
protected void onRestart() {
super.onRestart();
}
onPause(), onResume()
protected void onPause() {
super.onPause();

protected void onResume() {


super.onResume();
}
onStop(), onDestroy()
protected void onStop() {
super.onStop();

protected void onDestroy() {


super.onDestroy();
}
Toast Message
● A toast provides simple feedback about an operation in a small popup.
● It only fills the amount of space required for the message and the current activity
remains visible and interactive.
● Toasts automatically disappear after a timeout.
How to use Toast
● Instantiate a Toast object (e.g Toast t1 ; )
● Use makeText() method with the following information:
○ Context
○ Text or String to be displayed
○ Time length
● Use show() to display the Toast message
● Example:
Context context=getApplicationContext();
CharSequence msg=“This is a Toast”;
int length=Toast.LENGTH.SHORT;
Toast t=Toast.makeText(context,msg,length).show();
Adding Vector Asset
● Vector Assets in Android Studio helps to add material icons and import Scalable
Vector Graphics (SVG) and Adobe Photoshop Document files into your project
as vector drawable resources.
● Image scalability is the major advantage of using the vector drawable.
● There are many formats of vector asset files:
○ Ai
○ Svg
○ Pdf
○ Eps
● Follow the following steps to implement vector assets
Implement Vector Asset
● Step 1: Right-click on drawable > New > Vector Asset
● After clicking on Vector Asset a new dialog box is opened that is shown below.
● Step 2: Click on Clip Art and Search for the Icons and click ok button
● Step 3: Change the color of the icon
● Step 4: Click Next Step
● 5: Now Click on Finish Button
● Step 6: Icon is created in the drawable folder
● Now you can refer it to in your xml file
Image Asset
● Helps you generate your own app icons from material icons, custom
images, and text strings.
● Follow the following step to include Image asset
● Step 1: First click on drawable > New > Image Asset.
● Step 2: Then a new dialog box will appear. Here click on the Clip Art Image.
● Step 3: Then search for the image you are looking for. And then click on the icon and
click on Ok in the bottom right.
● Step 4: Now Click on Next.
● Step 5: Click on Finish.

You might also like