0% found this document useful (0 votes)
40 views27 pages

Note

The document discusses Android architecture and components. It explains that Android uses the Linux kernel and includes native libraries and a runtime environment. It also describes activities, fragments, services and their lifecycles. Key Android SDK tools and the process of creating an Android Virtual Device are summarized.
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)
40 views27 pages

Note

The document discusses Android architecture and components. It explains that Android uses the Linux kernel and includes native libraries and a runtime environment. It also describes activities, fragments, services and their lifecycles. Key Android SDK tools and the process of creating an Android Virtual Device are summarized.
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/ 27

+++Chapter-1

1) introduction to android?

 Android is an Operating System and programming platform developed


by Google.
 It supports devices like mobile phones and other devices, such as
tablets, watch, TV, & auto.
 Android includes a Software Development Kit (SDK) that helps you
write code and assemble software modules to create apps for
Android users.
 Android also provides a marketplace (Play Store) to distribute
apps.
 It conquered around 75% of the global market share by the end
of 2020.
 The company named Open Handset Alliance developed Android for
the first time that is based on the modified version of the Linux
kernel and other open-source software.
 In September 2008, the first Android-powered device launched in
the market.
2) Explain android architecture with diagram?

1. Linux kernal:

 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 features of Linux kernel are:

 Security
 Memory Management
 Process Management
 Network Stack
 Driver Model

2. Platform libries:

 Libraries carry a set of instruction to guide the device in


handling different type of data.
 Above Linux kernal there are native libraries such as
SQLite,Webkit,OpenGL,SSL,etc.

 Some of these libraries are briefly explained below.

i. SQLite: it provides various classes used for database management.


ii. WebKit: it is a web browser engine used to display internet
content.
iii. SSL: it provides internet security.
iv. OpenGL: it is a java interface to OpenGl ES 3D graphics rendering
api.

3. Android 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)
 These core libraries enable android developers to write android
applications using standard java programming language.
 DVM is a major component of android OS.it is same as like java
virtual machine.
 DVM is responsible for running android applications.
 It consumes less memory and provide very fast performance.
4. Application framework:

 It provides various api’s like activity manager, resource


manager,content provider,telephony manger,etc.
 These api are used by android application developers.

5. application layer:

 Applications layer is present at the top.


 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.

3) List and Explain components of android SDK

 The Android Software Development Kit (SDK) is a collection of


software tools and libraries provided by Google to develop
applications for the Android platform. It consists of various
components that enable developers to build, test, and debug
Android applications. Here are the key components of the Android
SDK:

I. Android Debug Bridge (ADB): A versatile command-line tool that


allows communication between a development machine and an Android
device/emulator. It is used for installing, debugging, and
managing applications on Android devices.
II. Android Emulator: A virtual device that emulates an Android
device, allowing developers to test and debug their applications
without requiring a physical device. The Android Emulator
simulates various device configurations and Android versions.
III. Android Development Tools (ADT) Plugin: A set of Eclipse
plugins that provide an integrated development environment (IDE)
for Android app development. It includes features like project
management, code editing, debugging, and UI design tools.
IV. Android SDK Tools: These are command-line utilities that are used
for various development tasks, such as building and packaging
Android applications. The SDK Tools include tools like AAPT
(Android Asset Packaging Tool), DX (Dalvik Executable), and other
utility scripts.
V. Android Support Library: A collection of libraries that provide
backward compatibility and additional features for older Android
versions. The support library includes components like AppCompat,
RecyclerView, ViewPager, and more.
VI. Android Build Tools: A collection of command-line tools used for
building and packaging Android applications. It includes tools
like AAPT2 (Android Asset Packaging Tool 2.0), D8 (Dexer 8), and
the Android Debug Bridge (ADB).
VII. Android System Images: These are pre-configured virtual machine
images that provide the Android operating system and various
device configurations for use with the Android Emulator.
VIII. Android NDK (Native Development Kit): This component allows
developers to build performance-critical parts of an application
using native code languages like C and C++. The NDK provides a
set of tools and libraries to compile, debug, and package native
code for Android.

4) What is AVD? Explain the process of creating AVD in Android


application.

 AVD stands for Android Virtual Device. It is a virtual device


that emulates an Android device and allows developers to test
their applications without needing a physical device. AVDs are
created and managed using the Android Virtual Device Manager,
which is part of the Android SDK tools.
 Here is the process of creating an AVD in an Android application:

1. Launch Android Studio


2. Open AVD Manager
3. Create a new AVD
4. Select a device definition
5. Select a system image
6. Download missing components
7. Configure AVD settings
8. Finish AVD creation
9. Launch AVD
10.Test your application
5) Write a note on “android framework”.

 Activity Manager: Manages the lifecycle and execution of


activities in an application, including creating, starting,
pausing, resuming, and destroying activities.
 Resource Manager: Handles the management and access of
application resources such as images, strings, and layouts.
Provides a way to organize and retrieve resources dynamically at
runtime.
 Content Provider: Enables secure and structured access to shared
data between applications. Acts as an interface for accessing and
manipulating data stored in databases or other sources.
 Telephony Manager: Provides access to telephony-related
information and services on a device, such as device IMEI, SIM
card details, network operator information, and call state.
Allows interaction with telephony features like making phone
calls and sending SMS messages.
 Package Manager: Manages the installation, upgrade, and removal
of applications on an Android device. Keeps track of installed
applications, enforces permissions, and allows querying and
accessing application metadata and resources.
Chapter-2
1) What is activity?

 Activity is a core component of an application that represents a


single screen with a user interface.
 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.

2) Write a note on: Activity Life Cycle.


Method Description
onCreate called when activity is first created.
onStart called when activity is becoming visible to the user.
onResume called when activity will start interacting with the user.
onPause called when activity is not visible to the user.
onStop called when activity is no longer visible to the user.
onRestart called after your activity is stopped, prior to start.
onDestroy called before the activity is destroyed.

3) Give Difference between Service, Intent Service, AsyncTask and


Threads.

4) Explain fragmentation and its life cycle?

 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.

 Life cycle of fragmentation


No. Method Description
it is called only once when it is
1) onAttach(Activity)
attached with activity.
It is used to initialize the
2) onCreate(Bundle)
fragment.
onCreateView(LayoutInflater, creates and returns view
3)
ViewGroup, Bundle) hierarchy.
It is invoked after the
4) onActivityCreated(Bundle)
completion of onCreate() method.
It provides information to the
fragment that all the saved state
5) onViewStateRestored(Bundle)
of fragment view hierarchy has
been restored.
6) onStart() makes the fragment visible.
7) onResume() makes the fragment interactive.
is called when fragment is no
8) onPause()
longer interactive.
is called when fragment is no
9) onStop()
longer visible.
allows the fragment to clean up
10) onDestroyView()
resources.
allows the fragment to do final
11) onDestroy()
clean up of fragment state.
It is called immediately prior to
12) onDetach() the fragment no longer being
associated with its activity.

5) Explain intent?

 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.
 An Intent is an object used to request an action from another app
component via the Android system.
 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.


I. Implicit Intent
II. Explicit Intent

I. Implicit Intent:
 Asks system to find an Activity that can handle this request.
 Find an open store that sells green tea
 Clicking Share opens a chooser with a list of apps

Example:

Show a web page


Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

Dial a phone number


Uri uri = Uri.parse("tel:8005551234");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);

II. Explicit Intent:


 Starts a specific Activity.
 Request tea with milk delivered by Nikita
 Main activity starts the ViewShoppingCart Activity
Example:
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);
Chapter-3
1) Discuss different layout in android with suitable examples.

 Android provides various layout managers to help you arrange UI


components in your application.
 Here are some of the commonly used layout in android with
suitable example.
1. LinearLayout:
LinearLayout arranges child views in either a
horizontal or vertical orientation. It can be nested inside
other layouts to create more complex UI structures.

<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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, Android!" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />

</LinearLayout>

2. RelativeLayout:
RelativeLayout allows you to position child
views relative to each other or relative to the parent layout.
You can use attributes like android:layout_alignParentTop,
android:layout_toEndOf

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_toEndOf="@+id/button1" />

</RelativeLayout>

3. FrameLayout:
FrameLayout is a simple layout that allows one
child view to be displayed at a time. It's often used for
displaying fragments or swapping views dynamically.

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image1" />

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

</FrameLayout>

4. ConstraintLayout:
ConstraintLayout allows you to define
complex layouts with flexible positioning and constraints. It's
powerful and efficient for building responsive UIs.
<ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, Android!" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView1" />

</ConstraintLayout>

2) What is view? How to create view and layouts.

 If you look at your mobile device,every user interface element


that you see is a View.
 View is a basic building block of a user interface.
 Display text (TextView class), edit text (EditText class)
 Buttons (Button class), menus, other controls
 Scrollable (ScrollView, RecyclerView)
 Show images (ImageView)
 Group views (ConstraintLayout and LinearLayout)

 Create views and layouts


1. Android Studio layout editor: visual representation of XML
2. XML editor
3. Java code

3) Explain view group?

 The ViewGroup class is a subclass of the View class. And also it


will act as a base class for layouts and layouts parameters.
 The ViewGroup will provide an invisible container to hold other
Views or ViewGroups and to define the layout properties. For
example, Linear Layout is the ViewGroup that contains UI controls
like Button, TextView, etc., and other layouts also.

 Root view is always a ViewGroup.

View ViewGroup
View is a simple rectangle
ViewGroup is the invisible container.
box that responds to the
It holds View and ViewGroup
user’s actions.
View is the SuperClass of All ViewGroup is a collection of
component like TextView, Views(TextView, EditText, ListView,
EditText, ListView, etc etc..), somewhat like a container.
A View object is a component
A ViewGroup object is a layout, that
of the user interface (UI)
is, a container of other ViewGroup
like a button or a text box,
objects (layouts) and View objects
and it’s also called a
(widgets)
widget.
For example, LinearLayout is the
Examples are EditText,
ViewGroup that contains Button(View),
Button, CheckBox, etc.
and other Layouts also.
View refers to the ViewGroup refers to the
android.view.View class android.view.ViewGroup class
android.view.View which is
ViewGroup is the base class for
the base class of all UI
Layouts.
classes.
4) Explain ListView?

 ListView is a ViewGroup that is used to display the list of items


in multiple rows and contains an adapter that automatically
inserts the items into the list.
 The main purpose of the adapter is to fetch data from an array or
database and insert each item that placed into the list for the
desired result.
 For displaying the items in the list method setAdaptor() is used.
setAdaptor() method conjoins an adapter with the list.

Attribute Description
android:divider A color or drawable to separate list items.
android:dividerHeight Divider’s height.
Reference to an array resource that will
android:entries
populate the ListView.

5) Explain recycle view?

 RecyclerView is a ViewGroup added to the android studio as a


successor of the GridView and ListView.
 To implement a basic RecyclerView three sub-parts are needed.

1. The Card Layout: The card layout is an XML layout which will be
treated as an item for the list created by the RecyclerView.
2. The ViewHolder: The ViewHolder is a java class that stores the
reference to the card layout views that have to be dynamically
modified during the execution of the program by a list of data
obtained either by online databases or added in some other way.
3. The Data Class: The Data class is a custom java class that acts
as a structure for holding the information for every item of
the RecyclerView.

 The Adapter: The adapter is the main code responsible for


RecyclerView. It holds all the important methods dealing with the
implementation of RecylcerView. The basic methods for a
successful implementation are:
 onCreateViewHolder: which deals with the inflation of the card
layout as an item for the RecyclerView.
 onBindViewHolder: which deals with the setting of different
data and methods related to clicks on particular items of the
RecyclerView.
 getItemCount: which Returns the length of the RecyclerView.
 onAttachedToRecyclerView: which attaches the adapter to the
RecyclerView.

RecyclerView ListView
The RecyclerView’s adaptor forces us The ListView doesn’t give that
to use the ViewHolder pattern. The kind of protection by default,
views are split into so without implementing the
onCreateViewholder() and ViewHolder pattern inside the
onBindViewholder() methods. getView().
Efficient Scrolling, we can choose
Inefficient scrolling, we can
the way of scroll-like vertically or
only create vertical scrolling.
horizontally and grids.
More memory is used for a long
Use of less memory. list. Sometimes devices get
hanged.
Animations using ItemAnimator are
easy and smooth. Animations like list
It’s complex to use Animation
appearance and disappearance, adding
and hard to handle it.
or removing particular views, and so
on.
Dividers between items are not shown Dividers between items are
by default. shown by default.
Use ItemDecorations to add margins ItemDecorations require
and draw on or under an item View. customization.

6) Explain menu and its type?

 Menu is an important part of the UI component which is used to


provide some common functionality around the application.
 With the help of menu, users can experience a smooth and
consistent experience throughout the application.

 There are three type of menu


1. Options menu`
2. Context menu
3. Popup menu
1. Options menu:

 The options menu is also known as the overflow menu.


 It is a standard menu that appears when a user press the menu or
when they press the three dot icon that appears in the appbar.
 The options menu is the primary collection of menu items for an
activity. It's where you should place actions that have a global
impact on the app, such as "Search," "Compose email," and
"Settings."
 It can be created using the onCreateOptionsMenu() method.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}

2. Context menu:

 A context menu is a floating menu that appears when the user


performs a long-click on an element.
 It provides actions that affect the selected content or context
frame.
 The context mnu can be created using the onCreateContextMenu()
method.

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}

3. popup menu:

 The popup menu is a menu that appears when a user taps on a


button or other clickable view in the user interface.
 It can be use to provide a list of options related to the current
task or activity such as sorting option or filtering option.
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.actions, popup.getMenu());
popup.show();
}
Chapter-4

1) Storage in android.

 In Android, there are 2 types of storages are available in


android.
 Data storage (Databases, SQLite, Realm, etc..).
 File storage (SD Card, Phone Storage).
 The system provides several options for you to save your app data.
 App-specific storage: Store files that are only used for your
application, either in dedicated directories within an
internal storage or different dedicated directories within
external storage.
 Shared Storage: Store files that your app intends to share with
other apps, including media, documents, and other files.
 Preferences: Store private, primitive data in key-value pairs
inside root directories in xml format.
 Databases: Store structured data in a private database using
the Room persistence library.
 When storing sensitive data that shouldn't be accessible from any
other app use internal storage, preferences, or a database.
 Internal storage has the added benefit of the data being hidden
from users.

2) Explain Internal Storage

 Uses private directories just for your app.


 App always has permission to read/write.
 Permanent storage directory—getFilesDir().
 Temporary storage directory—getCacheDir().

File file = new File(


context.getFilesDir(), filename);

 Use standard java.io file operators or streams to interact with


files.
3) Explaim External Storage

 External storage such as SD card can also store application data,


there’s no security enforced upon files you save to the external
storage. In general there are two types of External Storage:

 Primary External Storage: In built shared storage which is


“accessible by the user by plugging in a USB cable and
mounting it as a drive on a host computer”. Example: When we
say Nexus 5 32 GB.
 Secondary External Storage: Removable storage. Example: SD Card.

 Set permissions in Android Manifest Write permission includes


read permission.

<uses-permission

android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission

android:name="android.permission.READ_EXTERNAL_STORAGE" />

 Always check availability of storage

public boolean isExternalStorageWritable() {

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {

return true;

return false;

 getExternalStorageState() is a static method of Environment to


determine if external storage is presently available or not. As
you can see if the condition is false we’ve disabled the save
button.
1. Environment.getExternalStorageState(): returns path to
internal SD mount point like “/mnt/sdcard”
2. getExternalFilesDir(): It returns the path to files folder
inside Android/data/data/application_package/ on the SD card.
It is used to store any required files for your app (like
images downloaded from web or cache files). Once the app is
uninstalled, any data stored in this folder is gone too.

4) What is Shared Preferences?

 Read and write small amounts of primitive data as key/value


pairs to a file on the device storage
 SharedPreference class provides APIs for reading, writing, and
managing this data
 It stores data until you clear the preference or uninstall the
app from device.
 In order to use shared preferences, you have to call a method
getSharedPreferences().

SharedPreferences sharedpreferences =
getSharedPreferences(“Settings”, Context.MODE_PRIVATE);

 Mode of shared preferences(SP).

1. MODE_PUBLIC will make the file public which could be


accessible by other applications on the device
2. MODE_PRIVATE keeps the files private and secures the user’s
data.
3. MODE_APPEND is used while reading the data from the SP file.

Nested classes of Shared Preferences

1. SharedPreferences.Editor: Interface used to write(edit) data in


the SP file. Once editing has been done, one must commit() or
apply() the changes made to the file.
2. SharedPreferences.OnSharedPreferenceChangeListener(): Called
when a shared preference is changed, added, or removed. This
may be called even if a preference is set to its existing value.
This callback will be run on your main thread.
Following are the methods of Shared Preferences

1. contains(String key): This method is used to check whether the


preferences contain a preference.

2. edit(): This method is used to create a new Editor for these


preferences, through which you can make modifications to the
data in the preferences and atomically commit those changes
back to the SharedPreferences object.

3. getAll(): This method is used to retrieve all values from the


preferences.

4. getBoolean(String key, boolean defValue): This method is used


to retrieve a boolean value from the preferences.

5. getFloat(String key, float defValue): This method is used to


retrieve a float value from the preferences.

6. getInt(String key, int defValue): This method is used to


retrieve an int value from the preferences.

7. getLong(String key, long defValue): This method is used to


retrieve a long value from the preferences.

8. getString(String key, String defValue): This method is used to


retrieve a String value from the preferences.

9. getStringSet(String key, Set defValues): This method is used


to retrieve a set of String values from the preferences.

10.registerOnSharedPreferencechangeListener(SharedPreferences.OnS
haredPreferencechangeListener listener): This method is used
to register a callback to be invoked when a change happens to a
preference.

11. unregisterOnSharedPreferencechangeListener(SharedPreferences.O
nSharedPreferencechangeListener listener): This method is used
to unregister a previous callback.
5) Explain SQLite database?

 It is an open-source relational database.


 It is lighter version of SQL.
 Android comes with built in SQLite database implementation.
 In order to access this database,you don’t ned to establish any
kind of connection for it like JDBC,ODBC etc.
 Store data in tables of rows and columns (spreadsheet…)
 Field = intersection of a row and column
 Fields contain data, references to other fields, or references to
other tables
 Rows are identified by unique IDs
 Column names are unique per table

 Implements SQL database engine that is

 self-contained (requires no other components)


 serverless (requires no server backend)
 zero-configuration (does not need to be configured for your
application)
 transactional (changes within a single transaction in SQLite
either occur completely or not at all)

 SQLite support only three type of data.

1. Text(lik String)
2. Integer (like int)
3. Real(like double)

 The basic advantage of SQLite.

 It is a lightweight database.
 Required very little memory
 Am autometically manage database.
6) Content provider?

 A content provider component supplies data from one application


to other on request.
 such requests are handled by the method of the contentResolver
class.
 A content provider can be use tha data can be stored in
database,in files or even over a network.

 Content provider are a very important component that serves the


purpose of a relational database to store the data of
applications.
 The role of the content provider in the android system is like a
central repository in which data of the applications are stored
and it facilitates other applications to securely access and
modifies that data based on the user requirement.
 Android system allows the content provider to store the
application data in several ways.
 Users can manage to store the application data like
image,audio,videos and personal contact information by storing
them in SQLite database,in file,or even on a network.
 In order to share the data,content providers have certain
permissions that are used to grant or restrict the rights to
other application to interface with the data.
Chapter-5

1)

You might also like