0% found this document useful (0 votes)
12 views117 pages

Versions of Android

The document outlines the architecture of Android, which consists of five main components: the Linux kernel, native libraries, Android Runtime, Application Framework, and Applications. It also details the evolution of Android versions from 1.0 to 11, highlighting key features and improvements introduced in each version. Additionally, it describes the essential building blocks of an Android application, including Activities, Services, and Content Providers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views117 pages

Versions of Android

The document outlines the architecture of Android, which consists of five main components: the Linux kernel, native libraries, Android Runtime, Application Framework, and Applications. It also details the evolution of Android versions from 1.0 to 11, highlighting key features and improvements introduced in each version. Additionally, it describes the essential building blocks of an Android application, including Activities, Services, and Content Providers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 117

Android Architecture

Android architecture or
Android software stack is
categorized into five parts:
1. linux kernel
2. native libraries
(middleware),
3. Android Runtime
4. Application
Framework
5. Applications
Linux Kernel

● Linux Kernel is heart of the android architecture.

● It manages all the available drivers such as display drivers,


camera drivers, Bluetooth drivers, audio drivers, memory
drivers, etc. which are required during the runtime.

● The Linux Kernel will provide an abstraction layer between


the device hardware and the other components of android
architecture. It is responsible for management of memory,
power, devices etc.
The features of Linux kernel are:
● Security: The Linux kernel handles the security between the
application and the system.
● Memory Management: It efficiently handles the memory management
thereby providing the freedom to develop our apps.
● Process Management: It manages the process well, allocates
resources to processes whenever they need them.
● Network Stack: It effectively handles the network communication.
● Driver Model: It ensures that the application works properly on the
device and hardware manufacturers responsible for building their
drivers into the Linux build.
Native libraries (middleware)
The Native Libraries includes various C/C++ core libraries and Java based libraries such as
Media, Graphics, Surface Manager, OpenGL etc. to provide a support for android
development.
● Media library provides support to play and record an audio and video formats.
● Surface manager responsible for managing access to the display subsystem.
● SGL and OpenGL both cross-language, cross-platform application program
interface (API) are used for 2D and 3D computer graphics.
● SQLite provides database support and FreeType provides font support.
● Web-Kit This open source web browser engine provides all the functionality to
display web content and to simplify page loading.
● SSL (Secure Sockets Layer) is security technology to establish an encrypted link
between a web server and a web browser.
Application runtime

● Android Runtime environment is one of the most important part of Android.

● It contains components like core libraries and the Dalvik virtual


machine(DVM).

● Mainly, it provides the base for the application framework and powers our
application with the help of the core libraries.

● Like Java Virtual Machine (JVM), Dalvik Virtual Machine (DVM) is a


register-based virtual machine and specially designed and optimized for
android to ensure that a device can run multiple instances efficiently.
Application framework

● Application Framework provides several important classes which


are used to create an Android application.
● It provides a generic abstraction for hardware access and also helps
in managing the user interface with application resources.
● Generally, it provides the services with the help of which we can
create a particular class and make that class helpful for the
Applications creation.
● It includes different types of services activity manager, notification
manager, view system, package manager etc. which are helpful for
the development of our application.
Applications

● Applications is the top layer of android architecture.


● The pre-installed applications like home, contacts, camera, gallery
etc and third party applications downloaded from the play store like
chat applications, games etc.
● will be installed on this layer only. It runs within the Android run
time with the help of the classes and services provided by the
application framework.
Android Versions
The development of the Android operating system was started in 2003 by
Android, Inc.

Later on, it was purchased by Google in 2005. The beta version of Android OS
was released on November 5, 2007, while the software development kit (SDK)
was released on November 12, 2007.

The first Android mobile was publicly released with Android 1.0 of the T-Mobile
G1 (aka HTC Dream) in October 2008.

Google announced in August 2019 that they were ending the confectionery
scheme, and they use numerical ordering for future Android versions.

The first Android version which was released under the numerical order format
was Android 10.
API level :API Level is an integer value that uniquely identifies the framework API revision offered
by a version of the Android platform.
Android Version 1.0 to 1.1: No codename
Android officially publish its Android version 1.0 in September 2008.
It is the initial version of Android operating system. It supports Web
browser to show HTML and XHTML web pages, camera, access web email
server (POP3, IMAP4, and SMTP).
This version contains Google Calendar, Google Maps, Google Sync, Google
Search, Google Talk, Instant messaging, Media player, Notifications appear
in the status bar, wallpaper, YouTube video player, Alarm Clock, Calculator,
Dialer, Pictures (Gallery), Wi-Fi and Bluetooth support.
Android version 1.5: Cupcake
On April 27, 2009, the Android updated to 1.5 with the codename of the
dessert item (Cupcake). It has Linux kernel 2.6.27. It supports third-party
virtual keyboard, Video recording and playback in MPEG-4, Copy and paste
feature, Animated screen translations, auto-rotation option, ability to
upload a video to YouTube, upload photos to Picasa, check phone usage
history.
Android version 1.6: Donut
On September 15, 2009, Android 1.6 was released with the name Donut. It
contains numerous new features such as voice and text entry search,
bookmark history, contacts, web, "speak" a string of text, faster camera access,
user can select multiple photos for deletion, support text-to-speech engine,
WVGA screen resolutions.

Android version 2.0 to 2.1: Eclair


On October 26, 2009, Android 2.0 was released, whose codename was
Eclair. It was based on Linux kernel 2.6.29. It contains the several new
features as expanded account sync, Microsoft Exchange email support,
Bluetooth 2.1, ability to tap a Contact photo and select to call, SMS, ability to
search all saved SMS, MMS messages, delete the oldest message
automatically when the defined limit is reached, Minor API, bug fixes.
Android version 2.2 to 2.2.3: Froyo
On May 20, 2010, Android 2.2 (Froyo) was released based on Linux kernel
2.6.32. It contains several features as speed, memory, performance
optimization. JIT compilation, Integration of Chrome's V8, JavaScript
engine into the Browser application, support Android Cloud to Device
Messaging service, Adobe Flash support, security updates, and
performance improvement.

Android version 2.3 to 2.3.7: Gingerbread


On December 6, 2010, the Android 2.3 (Gingerbread) was released based on
Linux kernel 2.6.35. It includes the following changes: support for
extra-large screen size and resolutions, updated user interface design with
increased simplicity and speed, enhanced copy/paste functionality, select a
word by press-holding, support Near Field Communication (NFC),
headphone virtualization, new Download Manager.
Android version 3.0 to 3.2.6: Honeycomb
On February 22, 2011, Android 3.0 (Honeycomb) was launched for the first tablet for
Android-based on Linux kernel 2.6.36. It contains the features like "holographic" user
interface for tablet, added system Bar, simplified multitasking tapping Recent Application
in system Bar, redesign the keyboard making fast typing, quick access to camera
exposure, hardware acceleration, support for multi-core processor, UI refinements,
connectivity for USB accessories, support for joysticks and gamepads, high-performance
Wi-Fi lock, improved hardware support, Google Books, fixed data connectivity issues when
coming out of Airplane mode.

Android version 4.0 to 4.0.4: Ice Cream Sandwich


On October 19, 2011, Android 4.0.1 (Ice Cream Sandwich) was launched, which was based on
Linux kernel 3.0.1. It was the last version of officially support Adobe System Flash player. It
introduces the numerous new features: refinements to "Holo" interface with new Roboto
font family, separation of widgets in a new tab, integrated screenshot capture, improved
error correction on the keyboard, improved copy and paste functionality, build-in photo
editor, fixed minor bugs, improvement to graphics, spell-checking, better camera
performance.
Android version 4.1 to 4.3.1: Jelly Bean
On June 27, 2012, Google announced Android 4.1(Jelly Bean) in the Google I/O conference.
It is based on Linux kernel 3.0.31. It updates to following features: smoother user interface,
enhance accessibility, expandable notification, fixed bug on Nexus 7, one-finger gestures
to expand/collapse notifications, lock screen improvement, multiple user accounts (tablets
only), new clock application, Bluetooth low energy support, volume for incoming call, 4K
resolution support, native emoji support, bug fixes for the Nexus 7 LTE.

Android version 4.4 to 4.4.4: KitKat


On September 3, 2013, Google announced Android 4.4 (KitKat). Initially, its code name was
"Key Lime Pie". Google started on Google's Nexus 5 on October 31, 2013. The minimum
required amount of RAM should available to Android is 340 MB. The other devices with
less than 512 MB of RAM must report themselves as "low RAM" devices. It includes several
new features as clock no longer display bold hours, wireless printing capability, WebViews
are based on Chromium engine, sensor batching, built-in screen recording feature, better
application compatibility, camera application loads Google+ Photo instead of Gallery.
Android version 5.0 to 5.1.1: Lollipop
Android 5.0 "Lollipop" was initially named "Android L" on June 25, 2014. It was officially
introduced on November 12, 2014. Lollipop provides several features like redesigned user
interface, support for 64-bit CPUs, support for print previews, material design, Project Volta
for battery life improvement, multiple user accounts, audio input, and output through USB
devices, join Wi-Fi networks, support for multiple SIM cards, device protection,
high-definition voice calls, native Wi-Fi calling support.

Android version 6.0 - 6.0.1: Marshmallow


Android 6.0 "Marshmallow" was disclosed under the codename "Android M" on May 28,
2015, for Nexus 5 and Nexus 6 phones, Nexus 9 tablet.
On October 5, 2015, Android lunches "Marshmallow" for all android devices. It contains the
various new features as App Standby feature, introduce the Doze mode to save battery life,
native fingerprint reader support, run-time permission requests, USB-C support, Unicode
7.0 & 8.0 emoji support.
Android version 7.0 to 7.1.2: Nougat
Android 7.0 "Nougat" was the major release for the Android operating system. Its initial
codename was "Android N". It was first released as a developer preview on March 9, 2016,
with factory images for the Nexus device.
On August 22, 2016, the final preview built was released with following features: file-based
encryption, zoom in the screen, multi-window support, new Data Saver mode, JIT compiler
makes 75 percent faster app installation, picture-in-picture support, support manager APIs,
circular app icons support, send GIFs directly from the default keyboard, battery usage
alerts.

Android version 8.0 to 8.1: Oreo


Android 8.0 "Oreo" was the 8th major release of the Android operating system. It was first
released for developer preview on March 21, 2017. The final developer preview was released
on July 24, 2017.
On August 21, 2017, its stable version was released with several features: picture-in-picture
support, support for Unicode 10.0 emoji (5.0), restructured settings, adoptive icons,
notification channels, notification dots, 2 times faster boot time, Google Play Protect,
Integrated printing support, Neural network API, shared memory API, Android Oreo Go
Edition, autofill framework, automatic light, and dark themes.
Android version 9.0: Pie
Android 9.0 "Pie" was the ninth major version of the Android operating system. It was first
announced and preview launched by Google on March 7, 2018. It was officially released on
August 6, 2018. It has the following features: the clock has moved to the left of the
notification bar, the "screenshot" button has been added, battery percentage always
shown on display.

Android version 10:


Android 10 is the tenth extensive version of the Android operating system. Android 10 has
developed under the codename "Android Q". It was initially announced by Google on
March 13, 2019 and its first beta version was released on same day and its second beta was
released on April 3, 2019.
The stable version of Android 10 was released on September 3, 2019. It contains features
like new permissions to access location in the background, floating setting panel, support
for an AV1 video codec, support for biometric authentication, support the WPA3 Wi-Fi
security.
Android 11
Android 11 operating system is the eleventh big release of Android. It is the 18th
version of Android mobile OS, which was released on 8 September 2020. The
alphabetic naming system of Android, based on deserts, was stopped since
Android 10. So therefore, this operating system has branded with "Android 11".
Features included in Android 11
○ Conversations: Get all your message in one place.
○ Accessibility: Perceptive apps help us to control and navigate our phone
using voice command.
○ Device controls: Android 11 allows us to control all our connected
devices (IOT) from a single point.
○ Content capture: Android 11 comes with a screen recording feature that
captures our phone's current screen activity.
○ Predictive tools: By predicting our habits and patterns of working, it
suggests accordingly.
○ Privacy & security: Android 11 gives more security and privacy fixes to our
smartphone straight from Google Play.
○ Media: We can play music from other devices connected to our phones.
Android - Application Components
Application components are the essential building blocks of an Android application.

These components are loosely coupled by the application manifest file AndroidManifest.xml that describes
each component of the application and how they interact.

There are following four main components that can be used within an Android application −
1. Activities

● Activities are said to be the presentation layer of our applications.


● The UI of our application is built around one or more extensions of the Activity class.By
using Fragments and Views, activities set the layout and display the output and also
respond to the user’s actions.
● An activity is implemented as a subclass of class Activity.
● An activity represents a single screen with a user interface,in-short Activity performs
actions on the screen. For example, an email application might have one activity that
shows a list of new emails, another activity to compose an email, and another activity for
reading emails.
● If an application has more than one activity, then one of them should be marked as the
activity that is presented when the application is launched.

public class MainActivity extends Activity {

}
2. Services

Services are like invisible workers of our app.

These components run at the backend, updating your data sources and Activities, triggering Notification,
and also broadcast Intents.

They also perform some tasks when applications are not active. A service can be used as a subclass of class
Service:

public class ServiceName extends Service {


}

For example, a service might play music in the background while the user is in a different application, or it
might fetch data over the network without blocking user interaction with an activity.
3. Content Providers

● It is used to manage and persist the application data also typically interacts with the SQL database.
● They are also responsible for sharing the data beyond the application boundaries.
● The Content Providers of a particular application can be configured to allow access from other
applications, and the Content Providers exposed by other applications can also be configured.
A content provider should be a sub-class of the class ContentProvider.
● A content provider component supplies data from one application to others on request. Such requests
are handled by the methods of the ContentResolver class. The data may be stored in the file system,
the database or somewhere else entirely.
● A content provider is implemented as a subclass of ContentProvider class and must implement a
standard set of APIs that enable other applications to perform transactions.

public class contentProviderName extends ContentProvider {

public void onCreate(){}

}
4. Broadcast Receivers

They are known to be intent listeners as they enable your application to listen to the Intents that satisfy the
matching criteria specified by us. Broadcast Receivers make our application react to any received Intent
thereby making them perfect for creating event-driven applications.
● Broadcast Receivers simply respond to broadcast messages from other applications or from the
system.
● For example, applications can also initiate broadcasts to let other applications know that some data
has been downloaded to the device and is available for them to use, so this is broadcast receiver who
will intercept this communication and will initiate appropriate action.
● A broadcast receiver is implemented as a subclass of BroadcastReceiver class and each message is
broadcaster as an Intent object.

public class MyReceiver extends BroadcastReceiver {

public void onReceive(context,intent){}

}
Additional Components
There are additional components which will be used in the construction of above mentioned entities, their
logic, and wiring between them. These components are −
Activities
● An application typically has multiple activities, and the user flips back and
forth among them.
● As such, activities are the most visible part of your application.
● Just like a website consists of multiple pages, so does an Android
application consist of multiple activities.
● As a website has a “home page,” an Android app has a “main” activity,
usually the one that is shown first when you launch the application.
● And just like a website has to provide some sort of navigation among
various pages, an Android app should do the same.
● We can jump from an activity of one application to another activity in a
completely separate application.

● For example, if you are in your Contacts app and you choose to text a friend, you’d be
launching the activity to compose a text message in the Messaging application.
Activity
Life Cycle
onCreate()
● It is called when the activity is first created.
● This is where all the static work is done like creating views, binding data to lists,
etc.
● This method also provides a Bundle containing its previous frozen state, if there
was one.

onStart()
● It is invoked when the activity is visible to the user.
● It is followed by onResume() if the activity is invoked from the background.
● It is also invoked after onCreate() when the activity is first started.

onRestart()
● It is invoked after the activity has been stopped and prior to its starting stage.
● Thus is always followed by onStart() when any activity is revived from background
to on-screen.
onResume()
● It is invoked when the activity starts interacting with the user.
● At this point, the activity is at the top of the activity stack, with a user
interacting with it.
● Always followed by onPause() when the activity goes into the
background or is closed by the user.

onPause()
● It is invoked when an activity is going into the background but has not
yet been killed.
● It is a counterpart to onResume().
● When an activity is launched in front of another activity, this callback
will be invoked on the top activity (currently on screen).
● The activity, under the active activity, will not be created until the
active activity’s onPause() returns, so it is recommended that heavy
processing should not be done in this part.
onStop()
● It is invoked when the activity is not visible to the user.
● It is followed by onRestart() when the activity is revoked from the
background, followed by onDestroy().
onDestroy()
● onDestroy() is called before the activity is destroyed.
● The activity is finishing due to the user completely dismissing the
activity or due to finish() being called on the activity.
● The system is temporarily destroying the activity due to a
configuration change ex. device rotation or multi-window mode.
onStop()
● It is invoked when the activity is not visible to the user.
● It is followed by onRestart() when the activity is revoked from the
background, followed by onDestroy().
onDestroy()
● onDestroy() is called before the activity is destroyed.
● The activity is finishing due to the user completely dismissing the
activity or due to finish() being called on the activity.
● The system is temporarily destroying the activity due to a
configuration change ex. device rotation or multi-window mode.
Intents
● An intent is to perform an action on the screen.
● It is mostly used to start activity, send broadcast receiver, start
services and send message between two activities.
● It is a messaging object which tells what kind of action to be
performed.
● The intent’s most significant use is the launching of the activity.
Body of Intent:
● action: The general action to be performed, such as ACTION_VIEW,
ACTION_EDIT, ACTION_MAIN, etc.
● data: The data to operate on, such as a person record in the contacts
database, expressed as a Uri
Basically two intents are there in android.
● Implicit Intents
● Explicit Intents
Implicit Intent
For Example: In the below images, no component is specified, instead, an action is performed i.e. a webpage
is going to be opened. As you type the name of your desired webpage and click on the ‘CLICK’ button. Your
webpage is opened.
Explicit Intent
For Example: In the below example, there are two activities (FirstActivity, and SecondActivity). When you
click on the ‘GO TO OTHER ACTIVITY’ Button in the FirstActivity, then you move to the SecondActivity.
When you click on the ‘GO TO HOME ACTIVITY’ button in the SecondActivity, then you move to the first
activity. This is getting done through Explicit Intent.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.javatpoint.com.implicitintent.MainActivity">

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:ems="10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginLeft="156dp"
android:layout_marginTop="172dp"
android:text="Visit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
</android.support.constraint.ConstraintLayout>
MainActivity.java

package example.javatpoint.com.implicitintent;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

Button button;
EditText editText;

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

button = findViewById(R.id.button);
editText = findViewById(R.id.editText);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
}
}
Android Explicit Intent
Android Explicit intent specifies the component to be invoked from activity. In other words, we can call another
activity in android by explicit intent.

We can also pass the information from one activity to another using explicit intent.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context="example.javatpoint.com.explicitintent.FirstActivity
">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="First Activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.454"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.06" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="392dp"
android:onClick="callFirstActivity"
android:text="Call first activity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
ActivityTwo class

package example.javatpoint.com.explicitintent;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class SecondActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Bundle extras = getIntent().getExtras();
String value1 = extras.getString("Value1");
String value2 = extras.getString("Value2");
Toast.makeText(getApplicationContext(),"Values are:\n First value: "+value1+
"\n Second Value: "+value2, Toast.LENGTH_LONG).show();
}
public void callFirstActivity(View view){
Intent i = new Intent(getApplicationContext(), FirstActivity.class);
startActivity(i);
}

}
Fragment
A Fragment represents a reusable portion of app's UI.
A fragment defines and manages its own layout, has its own
lifecycle, and can handle its own input events.
Fragments cannot live on their own they must be hosted by an
activity or another fragment.
Android Fragment is the part of activity, it is also known as
sub-activity.
There can be more than one fragment in an activity.
Using with fragment transaction. we can move one fragment to
another fragment.
Figure 1. Two versions of the same screen on different screen sizes. On the left, a
large screen contains a navigation drawer that is controlled by the activity and a grid
list that is controlled by the fragment. On the right, a small screen contains a bottom
navigation bar that is controlled by the activity and a linear list that is controlled by
the fragment.
Fragment
Life Cycle
onAttach():
The fragment instance is associated with an activity instance.
The fragment and the activity is not fully initialized.
Typically you get in this method a reference to the activity which uses the
fragment for further initialization work.
onCreate():
The system calls this method when creating the fragment.
You should initialize essential components of the fragment that you want to
retain when the fragment is paused or stopped, then resumed.
onCreateView() :
The system calls this callback when it's time for the fragment to draw its user
interface for the first time.
To draw a UI for your fragment, you must return a View component from this
method that is the root of your fragment's layout.
You can return null if the fragment does not provide a UI.
onActivityCreated():
The onActivityCreated() is called after the onCreateView() method when the host
activity is created.
Activity and fragment instance have been created as well as the view hierarchy of
the activity.

onStart():
The onStart() method is called once the fragment gets visible.

onResume():
Fragment becomes active.

onPause():
The system calls this method as the first indication that the user is leaving the
fragment.
This is usually where you should commit any changes that should be persisted
beyond the current user session.
onStop():
Fragment going to be stopped by calling onStop().

onDestroyView():
Fragment view will destroy after call this method.

onDestroy():
onDestroy() called to do final clean up of the fragment's state but Not
guaranteed to be called by the Android platform.
Android Emulator
● The Android emulator is an Android Virtual Device (AVD), which
represents a specific Android device.
● We can use the Android emulator as a target device to execute and test
our Android application on our PC.
● The Android emulator provides almost all the functionality of a real
device. We can get the incoming phone calls and text messages.
● It also gives the location of the device and simulates different network
speeds. Android emulator simulates rotation and other hardware
sensors. It accesses the Google Play store, and much more
● Testing Android applications on emulator are sometimes faster and
easier than doing on a real device. For example, we can transfer data
faster to the emulator than to a real device connected through USB.
● The Android emulator comes with predefined configurations for several
Android phones, Wear OS, tablet, Android TV devices.
Install the emulator
The Android emulator is installed while installing the Android Studio.

However some components of emulator may or may not be installed while installing Android Studio.
To install the emulator component, select the Android Emulator component in the SDK Tools tab of
the SDK Manager.

1. In Android Studio, we need to create an Android Virtual Device (AVD) that the emulator can use to
install and run your app. To create a new AVD:-

1.1 Open the AVD Manager by clicking Tools > AVD Manager.
1.2 Click on Create Virtual Device, at the bottom of the AVD Manager dialog.
Then Select Hardware page appears.
1.3 Select a hardware profile and then click Next. If we don?t see the
hardware profile we want, then we can create or import a hardware profile.
The System Image page appears.
1.4 Select the system image for the particular API level and click Next. This leads to
open a Verify Configuration page.
1.5 Change AVD properties if needed, and then click Finish.

2. In the toolbar, choose the AVD, which we want to run our app from the target
device from the drop-down menu.

3. Click Run.
Dalvik Virtual Machine(DVM)
Android DDM was written by Dan Bornstein, and Dalvik is the name of a town in
Iceland.

A Dalvik virtual machine enables Android applications to run in its own process with its
own instance.

Role of the Dalvik Virtual Machine


The Dalvik Virtual Machine(DVM) was the original machine which was used by Android
and it was replaced by Android RunTime(ART) when Android 5.0 was released.

It executed bytecode generated from APK’s, which are compiled from Java source code
into Dalvik Executable(DEX) files.
The Role of the DVM in Android includes:
● Optimizing the Virtual Machine for memory, battery life, and
performance
● Conversion of class files into .dex file through Dex compiler that runs on
Dalvik VM.
● Converting multiple class files into dex files.
The Dex compiler helps convert the class file into .dex file, the
following image shows how it flows:
● First of all the .java file converts into .class file with the help of Java
compiler.
● Next .class file converts into .dex file using Dec compiler.
● Then finally the packaging process is handled by the Android Assets
packaging (aapt) tools.
Features of Dalvik Virtual Machine
● Register-Based Architecture: Dalvik is a register-based virtual machine unlike the
traditional stack based one (like JVM). This helps minimize overhead that would be
incurred by constantly pushing and popping values off the stack making execution faster,
especially on low memory mobile devices.
● Optimized for Mobile Devices: It is an optimizing BSJ virtual machine that was designed
specifically to run on the Android operating system, with low memory and power
requirements. It virtualizes multiple apps by running a separate instance of the VM for
each application as it does best in simultaneously handling many applications.
● Dex Bytecode Execution: Dalvik uses. dex (Dalvik Executable) files—these compile the
source into a more compact bytecode in order to make it better-suited for low-memory
environments. We compile multiple Java classes into a single. dex file so that it was just
63% of the original size, meaning a small parse and load time on mobile devices.
● Just In Time (JIT) Compilation: Dalvik was released from Android 2.2 (Froyo)
and later included a JIT compiler to translate the bytecode into machine code
directly at execution runtime, which could eventually boost frequently
executed codes performance.
● Garbage Collection: The above code ran on the DALVIK which has automatic
garbage collection to make sure that apps will not consume large amount of
resources and thus there is no effect in system stability.
● Support for Multithreading: Dalvik is multithreading mobile machine can
have multiple threads at the same time for an application to work on. This
feature is one of the most required things when it comes to mobile apps e.g.,
background process along with foreground user tracking.
Advantages of DVM(Dalvik Virtual Machine)
● DVM supports the Android operating system only.
● In DVM executable is APK.
● Execution is faster.
● From Android 2.2 SDK Dalvik has it’s own JIT (Just In Time) compiler.
● Applications are given their own instances.

Disadvantages of DVM(Dalvik Virtual Machine)


● DVM supports only Android Operating System.
● For DVM very few Re-Tools are available.
● App Installation takes more time due to dex.
● More internal storage is required.
Application of Dalvik Virtual Machine
● Running Android Apps: It improves how apps run by using processing power
and less memory, ensuring smooth work.
● Support for Multitasking: It allows multiple android apps to run at the same time
without interrupting each other sped , making multi tasking smoother on mobile
devices.
● Memory Management: It manages memory more efficiently than older system,
making sure that apps can run well even on devices with limited memory.
Android UI
● Android provides a variety of Pre-built UI components.

● Layout objects and UI controls that allow you to build the graphical
user interface for your app.
● Android also provides other UI modules for special interfaces such
as dialogs, notifications, and menus.
Views
● View class represents the basic building block for user interface
components.
● A View occupies a rectangular area on the screen and is
responsible for drawing and event handling.
● All of the views in a window are arranged in a single tree.
● View is the base class for widgets, which are used to create
interactive UI components (buttons, text fields, etc.)
View Group
● A ViewGroup is a special view that can contain other views (called
children.)
● The view group is the base class for layouts and views containers.
● It’s child can be Views or View Group.
Layouts
● A layout defines the structure for a user interface in your activity, such as the
UI for an activity or app widget. You can declare a layout in two ways:
● Declare UI elements in XML. Android provides a straight forward XML
vocabulary that corresponds to the View classes and subclasses, such as
those for widgets and layouts.
● Instantiate layout elements at runtime. Your application can create View
and ViewGroup objects (and manipulate their properties) programmatically.
● All elements in the layout are built using a hierarchy of View and ViewGroup
objects.
● A View usually draws something the user can see and interact with.
● Layout(View Group) is an invisible container that defines the layout structure
for View and other Layout(View Group) objects.
● It provide a different layout structure, such as LinearLayout or
ConstraintLayout.
Common layouts in
Android are:
1) Linear Layout
2) Relative Layout
3) Table Layout
4) Frame Layout
dp (Density-independent
Pixels),
sp ( Scale-independent
Pixels),
pt ( Points which is 1/72 of an
inch),
px( Pixels),
mm ( Millimeters) and
in (inches).
android:layout_width=wrap_content tells your view to size itself to the dimensions required by its
content.

android:layout_width=fill_parent tells your view to become as big as its parent view.

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand
the rest of the ID string and identify it as an ID resource.

The plus-symbol (+) means that this is a new resource name that must be created and added to our
resources.

Density-independent pixels (dp) are units of measurement that scale to the same size on different screens.

Scale-independent Pixels," which is a unit of measurement used primarily for font sizes in user interfaces,
particularly on Android.

"Pt" stands for "point," and in typography, one point is defined as 1/72 of an inch; meaning that a single "pt" is
equal to 1/72 inch in measurement.

A pixel is the smallest unit of a digital image or display and stands for “picture element.”
Linear Layout
● LinearLayout is a view group that aligns all children in a single direction,
vertically or horizontally.
● You can specify the layout direction with the android:orientation attribute.
● Linear Layout can be created in two direction: Horizontal & Vertical.
● LinearLayout also supports assigning a weight to individual children with the
android:layout_weight attribute.
● This attribute assigns an important value to a view in terms of how much
space it should occupy on the screen.
● A larger weight value allows it to expand to fill any remaining space in the
parent view.
● All children of a Linear Layout are stacked one after the other, so a vertical list
will only have one child per row, no matter how wide they are, and a
horizontal list will only be one row high (the height of the tallest child, plus
padding).
● A Linear Layout respects margins between children and the gravity (right,
center, or left alignment) of each child.
<?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:paddingLeft="16dp"

android:paddingRight="16dp"

android:orientation="vertical" >

<EditText <EditText

android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/to" />
android:hint="@string/subject" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="@string/message" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/send" />
</LinearLayout>
Relative Layout
● RelativeLayout is a view group that displays child views in relative positions.
● The position of each view can be specified as relative to sibling elements or in
positions relative to the parent RelativeLayout area.
● As it allows us to position the component anywhere, it is considered as most flexible
layout.
● Relative layout is the most used layout after the Linear Layout in Android.
● In Relative Layout, you can use “above, below, left and right” to arrange the
component’s position in relation to other component.
● In this view group child views can be layered on top of each other.
● Relative Layout lets child views specify their position relative to the parent view or to
each other (specified by ID). So you can align two elements by right border, or
make one below another, centered in the screen, centered left,and so on.
● By default, all child views are drawn at the top-left of the layout, so you must define
the position of each view using the various layout properties available from
RelativeLayout. LayoutParams.
There are so many properties that are supported by relative layouts. Some of the most used properties are
listed below:

● layout_alignParentTop
● layout_alignParentBottom
● layout_alignParentRight
● layout_alignParentLeft
● layout_centerHorozontal
● layout_centerVertical
● layout_above
● layout_below
Step 1: Create a New Project
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml
and add the below code to that file. <Button
activity_main.xml: android:id="@+id/button1"
<?xml version="1.0" encoding="utf-8"?> android:layout_width="wrap_content"
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_marginTop="35sp"
android:layout_height="fill_parent" android:text="Top Left Button"
android:background="#168BC34A" android:layout_alignParentLeft="true"
xmlns:android="http://schemas.android.com/apk/ android:layout_alignParentTop="true"/>
res/android">
<Button
<Button
android:id="@+id/button2"
android:layout_width="wrap_content" android:id="@+id/button4"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_marginTop="35sp" android:layout_height="wrap_content"
android:text="Top Right Button" android:text="Bottom Right Button"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_alignParentRight="true"/
<Button
android:layout_alignParentBottom="true"/>
android:id="@+id/button3"
android:layout_width="wrap_content" <Button
android:layout_height="wrap_content" android:id="@+id/button5"
android:text="Bottom Left Button" android:layout_width="fill_parent"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:text="Middle Button"
android:layout_alignParentBottom="true"/> android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
3: Working with the MainActivity.java file
Go to the MainActivity.java/
MainActivity.kt file and refer to the
following code. Below is the code for
the MainActivity file. There is nothing
to write inside the MainActivity file.
Frame Layout
● Frame Layout Frame Layout is designed to block out an area on the
screen to display a single item.
● Generally, Frame Layout should be used to hold a single child view,
because it can be difficult to organize child
● views in a way that's scalable to different screen sizes without the
children overlapping each other.
● You can, however, add multiple children to a Frame Layout and
control their position within the Frame Layout by assigning gravity to
each child, using the android:layout_gravity attribute. Child views
are drawn in a stack, with the most recently added child on top.
● The size of the Frame Layout is the size of its largest child (plus
padding), visible or not (if the Frame Layout's parent permits).
Step 1: Create a New Project in Android Studio

Step 2: Working with the XML Files

All the views are placed on each other but we displace them according to our requirements.
First, we add an image in the background and add other widgets on the top.
On the screen, we can see the beautiful login page having an image in the background.

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/main"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="32dp"

android:background="@color/white"

tools:context=".MainActivity">
<TextView
<EditText
android:id="@+id/textView"
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:layout_marginTop="156dp"
android:layout_gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:background="@color/green"
android:background="@color/grey"
android:padding="16dp"
android:textColorHint="@color/white"
android:text="Login Details"
android:hint="Enter your email"
android:textColor="#FFFFFF"
android:padding="10dp" />
android:textSize="20sp" />
<EditText <Button
android:id="@+id/editText2"
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="300dp"
android:layout_marginTop="220dp"
android:backgroundTint="@color/green"
android:background="@color/grey"

android:textColorHint="@color/white" android:layout_gravity="center_horizontal"

android:hint="Enter password" android:text="Submit" />

android:padding="10dp" /> </FrameLayout>


Step 3: Working with the MainActivity File

import android.os.Bundle;
protected void onCreate(Bundle
import android.widget.EditText;
savedInstanceState) {
import android.widget.TextView;
super.onCreate(savedInstanceState);
import
androidx.appcompat.app.AppCompat setContentView(R.layout.activity_main);
Activity;
// finding the UI elements
public class MainActivity
extends AppCompatActivity { textView = findViewById(R.id.textView);

TextView textView; editText1 = findViewById(R.id.editText1)

EditText editText1,
editText2 = findViewById(R.id.editText2)
editText2;

@Override } }
Table Layout
● A layout that arranges its children into rows and columns.
● A Table Layout consists of a number of TableRow objects, each defining a row
(actually, you can have other children, which will be explained below).
● Table Layout containers do not display border lines for their rows, columns, or
cells.
● Each row has zero or more cells; each cell can hold one View object.
● The table has as many columns as the row with the most cells.
● A table can leave cells empty. Cells can span columns, as they can in HTML.
● The width of a column is defined by the row with the widest cell in that
column.
However, a Table Layout can specify certain columns as shrinkable or stretchable
by callingn setColumnShrinkable() or setColumnStretchable().

If marked as shrinkable, the column width can be shrunk to fit the table into its
parent object.

If marked as stretchable, it can expand in width to fit any extra space.

The total width of the table is defined by its parent container.

It is important to remember that a column can be both shrinkable and stretchable.


In such a situation, the column will change its size to always use up the available
space, but never more.
● You can hide a column by calling setColumnCollapsed().
● The children of a Table Layout cannot specify the layout_width attribute.
Width is always MATCH_PARENT.
● However, the layout_height attribute can be defined by a child; default value is
WRAP_CONTENT.
● If the child is a TableRow, then the height is always WRAP_CONTENT. Cells
must be added to a row in increasing column order, both in code and XML.
● Column numbers are zero-based. If you don't specify a column number for a
child cell, it will auto increment to the next available column.
● If you skip a column number, it will be considered an empty cell in that row.
Although the typical child of a Table Layout is a TableRow, you can actually
use any View subclass as a direct
● child of Table Layout. The View will be displayed as a single row that spans
all the table columns. Sample code showing use of TableLayout has been
shown below:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".MainActivity">
<!--add multiple rows here like the one below-->
<TableRow
android:background="@color/green"
android:padding="16dp">
<!--add multiple views here like the one below-->
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
<TableRow <View

android:background="@color/green" android:layout_width="wrap_content"

android:padding="16dp"> android:layout_height="wrap_content"/>

<!--sub view 1--> </TableRow>

<View

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<!--sub view 2-->

<View

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

<!--sub view 3-->


Activity_main.xml:
<TextView
<?xml version="1.0" encoding="utf-8"?>
android:id="@+id/txt"
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:id="@+id/main" android:text="ICC Ranking of Players:"
android:padding="32dp"
android:textSize = "20sp"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:textStyle="bold">
android:background="@color/white" </TextView>
tools:context=".MainActivity">
<TableRow <TextView
android:layout_width="wrap_content"
android:background="@color/green" android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"> android:gravity="center"
android:text="Player"
<TextView android:textStyle="bold" />
android:layout_width="wrap_content"
<TextView
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center"
android:gravity="center" android:text="Team"
android:textStyle="bold" />
android:text="Rank"

android:textStyle="bold" />
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:text="Points"

android:textStyle="bold" />

</TableRow>
ConstraintLayout

It is the latest layout which was introduced in 2016 and supports android
2.3 or higher version .
It is a viewgroup which allows us to create large and complex layouts
with a flat view hierarchy.
Its main advantage is that it reduces the nesting of view or viewgroup
which in order improves the performance.
It is very similar to relativelayout because it also makes the relationship
between multiple views.
Advantages of using ConstraintLayout in Android

● ConstraintLayout provides you the ability to completely design your UI with the drag-and-drop feature
provided by the Android Studio design editor.
● It helps to improve the UI performance over other layouts.
● With the help of ConstraintLayout, we can control the group of widgets through a single line of code.
● It helps to manage the position and size of views without using nested layouts which improves
performance and makes it easier.
● ConstraintLayout is more efficient than Linear or Relative layouts, especially for complex layouts, because
ConstraintLayout uses a more efficient algorithm to calculate the positions and sizes of widgets.

Disadvantages of using ConstraintLayout in Android

● When we use the Constraint Layout in our app, the XML code generated becomes a bit difficult to
understand.
● In most of the cases, the result obtain will not be the same as we got to see in the design editor.
● Sometimes we have to create a separate layout file for handling the UI for the landscape mode.
GridLayout
● Let us not get confused with GridView and GridLayout to be the
same.
● GridView simply gives us a two-dimensional view to display the
items on the screen, under ViewGroup. On the other hand,
GridLayout is a layout manager that arranges the views in a grid.
● GridLayout basically places its children in a rectangular grid. This
grid has a set of a number of thin lines that separate the view area
into cells.
● Suppose you have a grid of N columns, then we will have N+1 grid
indices that would be starting from 0.
<GridLayout <ImageButton
xmlns:android= “http://schemas.android.com/apk/res/android”
android: id= “@+id/GridLayout” android:id="@+id/imageButton1"
android: layout_width= “match_parent”
android: layout_height= “match_parent” android:layout_width="160dp"
</GridLayout>

Example: android:layout_height="90dp"

<?xml version="1.0" encoding="utf-8"?> android:layout_gravity="left|top"


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/scene1" />
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
<ImageButton
android:layout_height="match_parent"
tools:context=".MainActivity">
android:id="@+id/imageButton2"
<GridLayout
android:id="@+id/GridLayout1"
android:layout_width="match_parent" android:layout_width="160dp"
android:layout_height="match_parent"
android:columnCount="2" android:layout_height="90dp"
android:orientation="horizontal"
android:rowCount="4" android:layout_gravity="left|top"
tools:context=".GridXMLActivity"
tools:layout_editor_absoluteX=
"56dp" android:src="@drawable/scene2" />
tools:layout_editor_absoluteY=
"0dp">
<ImageButton <ImageButton
android:id= "@+id/imageButton3" android:id="@+id/imageButton6"
android:layout_width= "160dp" android:layout_width="160dp"
android:layout_height= "90dp" android:layout_height="90dp"
android:src= "@drawable/scene3" />android:layout_gravity="left|top"
<ImageButton
android:src="@drawable/scene6" />
android:id= "@+id/imageButton4"
</GridLayout>
android:layout_width= "160dp"
</androidx.constraintlayout.widge
android:layout_height= "90dp"
t.ConstraintLayout>
android:layout_gravity= "left|top"
android:src= "@drawable/scene4" />
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="160dp"
android:layout_height="90dp"
android:layout_gravity="left|top"
android:src="@drawable/scene5" />
Attributes of Android GridLayout
● android:alignmentMode – It sets the alignment of the
margins and the boundaries.
● android:columnCount – It sets the maximum number of
columns to create when positioning children automatically.
● android:columnOrderPreserved – It ensures that the
column boundaries appear in the same order as its column
indices.
● android:rowCount – It set the maximum no. of rows to create
when positioning children automatically.
● android:rowOrderPreserved -It ensures that the row
boundaries appear in the same order as its row indices.
● android:useDefaultMargins – It tells the GridLayout to use
margins if no margin is specified in the parameter. For this, it
needs to be set on True.
Android Toast
● Android Toast can be used to display information for the short period of time. A toast contains
message to be displayed quickly and disappears after sometime.

● The android.widget.Toast class is the subclass of java.lang.Object class.

● You can also create custom toast as well for example toast displaying image.

Toast class
Toast class is used to show notification for a particular interval of time. After sometime it disappears. It
doesn't block the user interaction.

Constants of Toast class


There are only 2 constants of Toast class which are given below.
Methods of Toast class
The widely used methods of Toast class are given below.

Android Toast Example


Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT).show();
Another code:

Toast toast=Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT);


toast.setMargin(50,50);
toast.show();
Here, getApplicationContext() method returns the instance of Context.
package example.javatpoint.com.toast;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//Displaying Toast with Hello Javatpoint message

Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT).show();

}
Android debugging
● The process of identifying and resolving issues with any Android application is
known as Android debugging.
● problems could arise from unexpected behaviour, faulty UI, logic errors, or
application failures.
● When developing an app, debugging might take place locally, in coding
environments, during quality assurance (QA) when errors are found, or in live
environments when users report difficulties.
● Typically, to debug an Android device, one needs to use debugging tools, create
breakpoints, log, or use a monitoring tool.
various methods of Android debugging
● Logcat: All log messages generated by the Android application are shown by Logcat.

To concentrate on certain problems, the logs can be filtered using tags, levels, and

other parameters. Several log levels are available off-the-shelf for printing messages

with logcat. These consist of functions such as Log.d(), Log.e(), and Log.i().
● Breakpoints: Breakpoints can be included in the code when debugging locally in
programmes such as Android Studio. The developer can step into or leap through the
code to move line by line and check the values of various variables, etc. in real time,
as the app reaches the breakpoint, which stops the workflow from executing. To
debug applications, conditional breakpoints can also be added.
● ADB(Android Debug Bridge): ADB is an effective built-in utility that developers can
use with a command line tool.
● DDMS (Dalvik Debug Monitor Service):This programme, which is a part of the ADB
Suite, allows users to take screenshots and monitor network activity.
● Android Profiler: Most IDEs, including Android Studio, have a profiler to help with
understanding CPU and local memory problems. Android Profiler also facilitates
quicker debugging of certain problems.
● Testing: In-depth testing of UT and QA bugs aids in problem understanding

and code level debugging prior to production deployment.

● Code reviews: A thorough code review also aids in better comprehending

code issues or errors, particularly the more challenging ones.

● Monitoring tools: Debugging production flaws can be aided by continual

crash tracking, logging, and user monitoring of issues in real time in

circumstances where the aforementioned tools are unavailable or difficult to

duplicate.
most common issues in Android
NullPointerException:
Error Example (Java):

String text = null;int length = text.length(); // This will throw a NullPointerException

Debugging & Fix (Java):

String text = null;if (text != null) {int length = text.length();}

ArrayIndexOutOfBoundsException:

Error Example (Java):

String text = null;if (text != null) {int length = text.length();}

Debugging & Fix (Java):

int[] numbers = {1, 2, 3};int index = 3;if (index >= 0 && index < numbers.length) {int value = numbers[index];}
IllegalStateException:

Error Example (Java/Kotlin):

fun performOperation() {if (someCondition) {throw IllegalStateException("Illegal


state for this operation")}// Rest of the code}

Debugging & Fix (Java):


fun performOperation() {if (someCondition) {throw IllegalStateException("Illegal
state for this operation")}// Rest of the code}

You might also like