Mad Unit 3
Mad Unit 3
Mad Unit 3
Unit- 1
Mobile Operating Systems
History of Android
• The code names of android ranges from A to L currently, such as Aestro, Blender, etc…
• OS
• Android application development on either of the following operating systems:
• Microsoft Windows.
• Mac OS X 10.5.8 or later version with Intel chip.
• Linux including GNU C Library 2.7 or later.
• Tools
• All the required tools to develop Android applications are freely available and can be
downloaded from the Web. Following is the list of software's you will need before you start
your Android application programming.
1. Java JDK6 or later version
2. Android Studio / Android SDK and Eclipse IDE for Java Developers (optional) and Android
Development Tools (ADT) Eclipse Plug-in (optional)
Requirements for Android
• The Java Development Kit (JDK) is a software development environment used for developing
Java applications and applets.
• It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler
(javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java
development.
• JVM
• JVM (Java Virtual Machine) is a specification that provides runtime environment in which
java bytecode can be executed.
• JVMs are available for many hardware and software platforms. JVM is a part of Java Run
Environment (JRE).
• The JVM performs following operation:
• Loads code
• Verifies code
• Executes code
• Provides runtime environment
• JRE
• The Java Runtime Environment (JRE) is a set of software tools for development of Java
applications. It combines the Java Virtual Machine (JVM), platform core classes and
supporting libraries.
Android SDK
• The Android SDK (software development kit) is a set of development tools used to develop
applications for Android platform. The Android SDK includes the following:
• Required libraries
• Debugger
• An emulator
• Relevant documentation for the Android application program interfaces (APIs)
• Sample source code
• Tutorials for the Android OS
Android Development Tools (ADT)
• The android developer tools let you create interactive and powerful application for android
platform.
• 1. Android Studio
• Developed by Google, Android Studio is an all-rounder integrated development
environment. Android has Gradle-base support that has features like visual layout editor,
intelligent code editor, real-time profilers and APK analyzer.
• 2. Visual Studio – Xamarin
• Xamarin was launched in 2011 which is the best free IDE for delivering an enterprise-
quality, cross-platform approach. Xamarin supplies add-ins to Microsoft Visual Studio that
allows developers to build Android, iOS, and Windows apps within the IDE
• 3. IntelliJ IDEA
• Using this IDE, you can do in-depth coding, quick navigation, and error analysis. It supports
mobile app development with the help of Java, Scala, Kotlin, Groovy.
• 4. Eclipse IDE
• It is one of the most popular IDES of Android apps. The open-source software is free to use.
Released under the Eclipse Public License, it holds a large community having plenty of
plugins and configurations. Highly customizable offers full support for Java programming
language and XML.
Android Virtual Devices (AVDs)
• 2. Click Create Virtual Device, at the bottom of the AVD Manager dialog. The Select
Hardware page appears.
Create a new AVD
• 3. Select a hardware profile, and then click Next. If you don't see the hardware profile you
want, you can create or import a hardware profile. The System Image page appears.
Create a new AVD
• 4. Select the system image for a particular API level, and then click Next. The Verify
Configuration page appears.
Create a new AVD
• The Android Emulator simulates Android devices on your computer so that you can test
your application on a variety of devices and Android API levels without needing to have
each physical device.
• The emulator provides almost all of the capabilities of a real Android device. You can
simulate incoming phone calls and text messages, specify the location of the device,
simulate different network speeds, simulate rotation and other hardware sensors, access the
Google Play Store, and much more.
• The emulator comes with predefined configurations for various Android phone, tablet, Wear
OS, and Android TV devices.
• In short, An Android emulator is an Android Virtual Device (AVD) that represents a
specific Android device. You can use an Android emulator as a target platform to run and
test your Android applications on your PC. Using Android emulators is optional.
• The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile
devices. It optimizes the virtual machine for memory, battery life and performance.
• The Dex compiler converts the class files into the .dex file that run on the Dalvik VM.
Multiple class files are converted into one dex file.
• Fig.: The compiling and packaging process from the source file
Dalvik Virtual Machine (DVM)
• The javac tool compiles the java source file into the class file.
• The dx tool takes all the class files of your application and generates a single .dex file. It is
a platform-specific tool.
• The Android Assets Packaging Tool (aapt) handles the packaging process.
Difference between JVM and DVM
DVM uses its own byte code and runs “.Dex” file. From JVM uses java byte code and runs “.class” file having
Android 2.2 SDK Dalvik has got a Just in Time compiler JIT (Just In Time).
DVM supports Android operating system only. JVM supports multiple operating systems.
For DVM very few Re-tools are available. For JVM many Re-tools are available.
There is constant pool for every application. It has constant pool for every class.
Unit- 2
Installation
• Java
1. Visit http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. Install it.
• Android Studio
3. Visit http://developer.android.com/sdk/index.html
4. click the button Download Android Studio.
5. Accept terms, and click Download.
6. Run executable file of setup.
7. Follow the setup wizard to install Android Studio and any necessary SDK tools.
8. On some Windows systems, the launcher script does not find where Java is installed. If
you encounter this problem, you need to set an environment variable indicating the
correct location.
9. Select Start menu > Computer > System Properties > Advanced System Properties.
Then open Advanced tab > Environment Variables and add a new system variable
JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\
jdk1.7.0_45
• launched android-studio-ide-181.5056338-windows.exe to start the installation process. The
installer responded by presenting the Android Studio Setup dialog box shown in Figure 1.
• To complete the installation, leave Start Android Studio box checked and click Finish.
• The first time Android Studio runs, it presents a Complete Installation dialog box that offers the
option of importing settings from a previous installation.
• choose not to import settings (the default selection) and click OK, the following splash screen
will appear:
Running Android Studio
• You will observe the following Finding Available SDK Components message box.
Running Android Studio
• Android Studio will present the following Android Studio Setup Wizard dialog box:
• Click Next, and the wizard will invite you to select an installation type. Keep the default
standard setting.
• Then you can choose a user interface theme.
• You can choose whichever you want and click Next. Android Studio will next provide the
opportunity to verify settings.
• click Finish and Android Studio will begin the process of downloading SDK components.
Running Android Studio
• It can take several minutes for this part of the setup to finish.
• Finally, click Finish to complete the wizard. The Welcome to Android Studio dialog box
appear.
• This dialog box is used to start up a new Android Studio project, work with an existing project,
and more. It can be accessed by selecting Android Studio from the Windows Start menu, or the
equivalent on another platform.
Mobile Application Development
Unit- 3
ANDROID APPLICATION DIRECTORY
STRUCTURE
• This file includes nodes for each of the Activities, Services, Content
Providers and Broadcast Receiver that make the application and
using Intent Filters and Permissions, determines how they co-ordinate
with each other and other applications.
• Java:
• The Java folder contains the Java source code files. These
files are used as a controller for controlled UI (Layout file).
It gets the data from the Layout file and after processing
that data output will be shown in the UI layout. It works on
the backend of an Android application.
• drawable:
• layout:
• A layout defines the visual structure for a user interface, such as the
UI for an Android application. This folder stores Layout files that are
written in XML language.
• <?xml version="1.0" encoding="utf-8"?>
• <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
• android:layout_width="match_parent"
• android:layout_height="match_parent"
• android:orientation="vertical" >
• <TextView android:id="@+id/text"
• android:layout_width="wrap_content"
• android:layout_height="wrap_content"
• <Button android:id="@+id/button"
• android:layout_width="wrap_content"
• android:layout_height="wrap_content"
• </LinearLayout>
• mipmap:
• Mipmap folder contains the Image Asset file that can be used in
Android Studio application. You can generate the icon types like
Launcher icons, Action bar and tab icons, and Notification icons.
• colors.xml:
• <resources>
• <string name="app_name"> Polytechnic</string>
• </resources>
• styles.xml:
• The styles.xml file contains resources of the theme style in the
Android application. This file is written in XML language. Below is a
sample styles.xml file:
• <resources>
• <!-- Base application theme. -->
• <style name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
• <!-- Customize your theme here. -->
• <item
name="colorPrimary">@color/colorPrimary</item>
• <item
name="colorPrimaryDark">@color/colorPrimaryDark</item>
• </style>
• </resources>
• build.gradle(Module: app):
• There are many types of layout. Some of which are listed below −
• Linear Layout
• Absolute Layout
• Table Layout
• Frame Layout
• Relative Layout
LINEAR LAYOUT
• Linear layout is further divided into horizontal and vertical layout. It
means it can arrange views in a single column or in a single row.
Here is the code of linear layout(vertical) that includes a text view.
• A layout that organizes its children into a single horizontal or vertical
row. It creates a scrollbar if the length of the window exceeds the
length of the screen
Linear Layout
• <?xml version=”1.0” encoding=”utf-8”?>
• <LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent” android:layout_height=”fill_parent”
android:orientation=”vertical” >
• <TextView
• android:layout_width=”fill_parent” android:layout_height=”wrap_content”
• android:text=”@string/hello” />
• </LinearLayout>
ABSOLUTELAYOUT
• The AbsoluteLayout enables you to specify the exact location of its
children. It can be declared like this.
• <AbsoluteLayout
• android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”http://schemas.android.com/apk/res/android” >
• <Button
• android:layout_width=”188dp”
android:layout_height=”wrap_content” android:text=”Button”
android:layout_x=”126px” android:layout_y=”361px” />
• </AbsoluteLayout>
TABLELAYOUT
<TableLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_height=”fill_parent” android:layout_width=”fill_parent” >
<TableRow>
<TextView android:text=”User Name:” android:width =”120dp” />
<EditText android:id=”@+id/txtUserName” android:width=”200dp” />
</TableRow> </TableLayout>
RELATIVELAYOUT
• RelativeLayout enforces to display elements in relations to each other. You
can specify that, for instance, one UI element can be said to be placed on
the left of another element, or on the bottom of another etc. Each UI
element can also be positioned according to the layout’s borders (e.g.
aligned to the right)
RELATIVELAYOUT
• It can be declared like this.
• <RelativeLayout
• android:id=”@+id/RLayout”
• android:layout_width=”fill_parent”
• android:layout_height=”fill_parent”
• xmlns:android=”http://schemas.android.com/apk/res/android” >
• </RelativeLayout>
FRAMELAYOUT
• The FrameLayout is a placeholder on screen that you can use to
display a single view. It can be declared like this.
1 layout_width
Specifies the width of the View or ViewGroup
2 layout_height
Specifies the height of the View or ViewGroup
3 layout_marginTop
Specifies extra space on the top side of the View or ViewGroup
4 layout_marginBottom
Specifies extra space on the bottom side of the View or ViewGroup
5 layout_marginLeft
Specifies extra space on the left side of the View or ViewGroup
6 layout_marginRight
Specifies extra space on the right side of the View or ViewGroup
7 layout_gravity
Specifies how child Views are positioned
8 layout_weight
Specifies how much of the extra space in the layout should be allocated to the View