Android Bit PDF
Android Bit PDF
Explain Activity life cycle with diagram yet interact with it fully. Life cycle flow
An Activity in Android represents a single 3. onResume() onCreate() → onStart() → onResume() →
screen with a user interface. Every When the activity comes to the onPause() → onStop() → onDestroy()
Android application may contain one or foreground and the user can interact with If the activity returns after stop:
more activities. The Activity life cycle is it, onResume() is called. At this point, the onRestart() → onStart() → onResume()
the sequence of callback methods through activity is in the running state. Importance of Activity life cycle
which an activity passes from its creation 4. onPause() Helps save user data during
to destruction. This helps Android manage This method is called when another interruptions
resources, app state, and user interaction activity comes partially in front of the Helps manage memory efficiently
efficiently. current activity. Here, unsaved data should Prevents data loss
Main callback methods of Activity life be committed and unnecessary operations Supports proper resource handling
cycle should be paused. Ensures smooth user experience
1. onCreate() 5. onStop()
This is the first callback method. It is This method is called when the activity The Activity life cycle is one of the most
called when the activity is created for the becomes completely hidden from the user. important concepts in Android. It controls
first time. In this method, the UI is The activity is no longer visible. how an activity is created, shown, paused,
initialized by calling setContentView() 6. onRestart() stopped, restarted, and destroyed.
and required controls are linked using If a stopped activity is restarted, Understanding this life cycle is necessary
findViewById(). onRestart() is called before onStart(). to build efficient Android applications.
2. onStart() 7. onDestroy()
After onCreate(), the onStart() method is This is the final callback method, called
called. In this stage, the activity becomes before the activity is destroyed. It is used
visible to the user but the user may not to release resources.
3) Explain SQLite in detail 4. Single File Storage 3. Create table setLockingEnabled()
SQLite is an open source relational The whole database is stored in one single Use execSQL() to execute SQL SQLite is one of the most important
database used in Android to store and file. This makes handling easy. statements such as creating a table. database tools in Android because it is
manage persistent data. Since it is 5. Supports SQL Syntax 4. Insert records easy to use, lightweight, fast, secure, and
embedded by default in Android, no SQLite supports most SQL commands Use ContentValues to store column-value built into Android. It is ideal for local
separate database server or additional such as CREATE, INSERT, UPDATE, pairs and insert() method to add records storage of application data.
setup is required. It is widely used for DELETE, and SELECT. into the table.
storing local application data such as login 6. ACID Transactions 5. Retrieve records
details, user profiles, records, messages, SQLite supports transactions, which Use rawQuery() and Cursor to read
and settings. ensures safe and reliable data operations. records from the table. Cursor methods
Why SQLite is used in Android Data types supported like moveToFirst() and moveToNext() are
1. Serverless SQLite mainly supports: used to traverse rows.
SQLite does not require a separate server Text for string values 6. Update and delete
process. The entire database works Integer for numbers and primary key Use update() and delete() methods to
directly through a local file. Real for decimal values modify or remove records.
2. Zero Configuration Steps to create and use SQLite database 7. Close connections
No installation or administration is 1. Create SQLiteDatabase object After database operations, close the cursor
needed. Import the SQLiteDatabase namespace and the database connection to avoid
3. Lightweight and create the object. memory leaks.
SQLite is small in size and suitable for 2. Open or create database Database properties
mobile devices with limited resources. Use openOrCreateDatabase() to open an Some properties that can be set are:
existing database or create a new one. setVersion()
setLocale()
4) Differentiate JSON and XML Differences between JSON and XML JSON generally does not support them in
JSON and XML are two common formats 1. Format the same way.
used for storing and exchanging data JSON uses key-value pairs. Example of JSON
between systems. Both are human XML uses tags. {
readable and both can be used to send data 2. Readability "name":"John",
from a server to an application. However, JSON is easier to read and write. "age":30
JSON is now used more widely because it XML is comparatively harder to read. }
is lightweight and easier to handle. 3. Size Example of XML
JSON JSON is shorter and more compact.
JSON stands for JavaScript Object XML is lengthy because of opening and <person>
Notation. It stores data as name/value closing tags. <name>John</name>
pairs and uses curly braces for objects and 4. Parsing <age>30</age>
square brackets for arrays. JSON can be parsed using [Link](). </person>
XML XML needs an XML parser JSON is preferred in modern applications
XML stands for Extensible Markup 5. Arrays because it is lightweight, compact, easier
Language. It stores data using tags and JSON supports arrays. to read, and faster to parse, while XML is
has both opening and closing tags. XML does not directly support arrays. useful when strict document structure is
Similarities between JSON and XML 6. Tags needed.
Both are self-describing JSON has no end tags.
Both are human readable XML uses start and end tags.
Both are hierarchical 7. Comments and namespaces
Both are used for data interchange XML supports comments and
Both can be parsed by many namespaces.
programming languages
5) Explain TextView, Button, 2. Button Use: Button → submits login form
ImageButton and EditText Button is a push button that performs an Used when image icons are preferred ImageButton → shows a clickable icon
Android provides many widgets to design action when the user clicks it. It is used in instead of text buttons. These four controls are essential for
the user interface. Among them, forms, navigation, submission, and 4. EditText Android UI design. TextView displays
TextView, Button, ImageButton, and commands. EditText is a subclass of TextView used text, Button performs actions,
EditText are basic and very important Important attributes of Button for accepting user input. It is commonly ImageButton shows clickable images, and
controls used in almost every Android android:id used in forms, search boxes, login pages, EditText accepts input. Together they help
application. android:text and registration pages. create interactive and user-friendly
1. TextView android:onClick Important attributes of EditText applications.
TextView is used to display text to the android:background android:id
user. It can show headings, labels, android:visibility android:text
messages, and other text on the screen. Use: android:editable
Important attributes of TextView Used for actions such as Save, Submit, android:background
android:id Next, Login, etc. android:visibility
android:text 3. ImageButton android:inputType
android:textColor ImageButton is a type of button that Use:
android:textSize displays an image instead of text. The user Used to enter name, password, phone
android:textStyle can press it just like a normal button. number, email, and other data.
android:hint Important attributes of ImageButton Example uses in one app
android:gravity android:src TextView → shows heading like
Use: android:id “Login Page”
Used to display non-editable text in the android:onClic EditText → accepts username and
app. android:background password
android:visibility
Write notes on a) Android Virtual 1. Hardware Profile 5. Dedicated Storage Area b) Android Emulators
Device (AVD) b) Android Emulators for This defines the hardware features of the Each AVD has its own dedicated storage The Android Emulator is a software tool
15 marks virtual device such as: area on the development machine. It that simulates an Android device on a
a) Android Virtual Device (AVD) screen size stores: computer. It helps developers run and test
An AVD is a set of hardware and software RAM installed applications Android applications without using a real
configuration details used by the Android camera user settings mobile phone. It works together with AVD
Emulator to run a virtual Android device sensors user data to provide a virtual testing environment.
on the computer. It enables developers to battery and other device features SD card contents Need for Android Emulator
test the app in different device 2. Mapping to a System Image This makes each AVD independent from Android Emulator is used because:
environments. This specifies the version of Android others. it allows testing without a physical
AVD is needed because: platform that runs on the virtual machine. AVD Manager device
it helps test Android applications By changing the system image, the same The AVD Manager provides an easy it supports different device types and
without a real phone application can be tested in different graphical interface to create, edit, and Android versions
it allows checking app behavior on Android versions. manage Android Virtual Devices. it makes testing and debugging easier
different Android versions 3. Emulator Skin Developers can quickly configure device it saves time and cost
it reduces the cost of buying many The emulator skin controls the screen type, system image, memory, and other Advantages
devices dimensions, look, and appearance of the options using this manager. saves cost and time
it helps in debugging and performance device. It gives the visual form of a Advantages of AVD easy and fast testing
checking smartphone, tablet, TV device, and so on. Easy testing of apps on virtual devices useful for debugging
it supports testing of screen size, 4. Emulated SD Card Supports multiple Android versions supports many virtual devices
storage, and hardware options An AVD can include an emulated SD card Useful for debugging Limitation
Components of AVD to store app files, media, and other data. No need for physical device every time Even though the emulator is useful, final
An AVD mainly consists of the following This helps in testing storage-related Can simulate different device testing on a real device is important
parts: features configurations because actual hardware performance may
differ.
Why Android is used in mobile Because of this openness, developers can 4. Support from Open Handset Alliance [Link] Availability of Development Tools
application development? for 15 marks build a wide variety of applications Android was introduced in 2007 along Android provides an SDK (Software
Android is widely used in mobile without many restrictions. It also reduces with the Open Handset Alliance (OHA). Development Kit) for application
application development because it is a development cost and encourages OHA includes companies such as Google, development. The Android SDK includes:
powerful, flexible, open source, and innovation. T-Mobile, Qualcomm, Motorola, software required libraries
developer-friendly platform. It is a Linux- 2. Linux-Based Operating System firms, semiconductor companies, and debugger
based operating system designed mainly Android is based on the Linux kernel, handset manufacturers. This strong emulator
for touch screen devices such as which makes it stable, secure, and industrial support helped Android grow documentation
smartphones and tablets. Android is not efficient. Linux provides good memory rapidly and become commercially 7. Emulator Support for Testing
just an operating system; it is a complete management, process management, and successful. Android development is supported by
software stack containing the operating system reliability. These qualities are very 5. Large Android Ecosystem emulator tools. With the help of AVD and
system, middleware, and key applications. important in mobile devices, where Android has a very large ecosystem. The emulator, developers can test applications
Because of its features and wide resources are limited and performance stakeholders of the Android ecosystem on virtual devices without needing a
acceptance, Android has become one of matters. include: physical smartphone every time. This
the most important platforms for mobile 3. Complete Software Stack Google saves time, cost, and effort during
app development. Android is used in mobile application OEMs (Original Equipment development.
1. Open Source Platform development because it provides a Manufacturers)
One of the main reasons for Android’s complete environment for app creation. It application development companies
popularity is that it is open source. This includes freelance Android developers
means the software can be freely modified operating system consumers
and distributed by device manufacturers, middleware
mobile carriers, and developers. key applications
Explain the following: b) Radio Button setting the default selected child radio e) Progress Bar
a. Check Box b. Radio Button c. Radio A RadioButton is a widget that provides button in the group A ProgressBar is used to show the
Group [Link] Button e. Progress multiple options, but the user can choose Uses of RadioGroup progress of a task. The notes say it is
BarExplain the following: only one option at a time. The notes Grouping radio buttons together helpful when a task like uploading or
a) Check Box clearly state that Radio Buttons are used Managing single selection downloading is taking place, so the user
A CheckBox is an on/off input control that inside a RadioGroup. This control is automatically can understand how much work is
allows the user to select one or more useful when choices are mutually Creating user-friendly form controls completed. It improves user experience by
options from a group. It is used when the exclusive, such as selecting gender, Avoiding multiple selections in single- giving feedback during long operations.
choices are not mutually exclusive, which payment mode, or language. choice questions This topic is also asked directly in the
means the user can select multiple items at Uses of RadioButton d) Toggle Button 2023 question paper
the same time. For example, in a form, a Gender selection A ToggleButton is a control used to Uses of ProgressBar
user can choose both “Music” and Yes/No type single choice represent two states such as ON/OFF or Showing download progress
“Sports” as interests. The notes describe Choosing one payment option Checked/Unchecked. The notes explain Showing upload progress
CheckBox as a selectable option control Selecting one answer in a quiz that it is useful when the user needs to Indicating app loading
and list common inherited view attributes c) Radio Group switch between two states, for example Displaying processing status
such as android:id, android:text, A RadioGroup is a container that holds turning sound, Wi-Fi, or Bluetooth on and Showing task completion percentage
android:background, android:onClick, and multiple RadioButtons. Its main purpose off. It is very useful in settings screens Types
android:visibility. is to organize RadioButtons and ensure Uses of ToggleButton Determinate ProgressBar – shows
Uses of CheckBox that only one of them can be selected at a Wi-Fi ON/OFF exact progress such as 40%, 70%, etc.
Selecting hobbies time. So, when the user selects one Bluetooth ON/OFF Indeterminate ProgressBar – shows
Accepting terms and conditions RadioButton, the others in the same Sound ON/OFF continuous animation when exact progress
Choosing multiple preferences RadioGroup become unselected Light/Dark mode switch is not known
Enabling or disabling optional settings [Link] notes mention the Any two-state setting
android:checkedButton property for
Explain any five attributes of CheckBox 4. android:onClick Explain TextView with example Example :
A CheckBox is an Android user interface This attribute specifies the method that TextView is one of the most commonly <TextView
control used when the user can select one should be called when the user clicks the used user interface controls in Android. It android:id="@+id/text_view_id"
or more options from a group. It is used in CheckBox. is used to display text on the screen such android:layout_width="wrap_content"
forms, settings, and option-selection 5. android:visibility as headings, labels, instructions, and android:layout_height="wrap_content"
screens where multiple choices are This controls whether the CheckBox is messages. It can be customized using android:text="Hello"
allowed. The notes explain that CheckBox visible, invisible, or hidden from the different attributes according to the need android:textStyle="bold|italic"
is suitable when options are not mutually layout. of the application. android:textColor="@color/black"/>
exclusive. Use Important attributes of TextView
Important attributes of CheckBox CheckBox is used in: 1. android:id
1. android:id hobbies selection It uniquely identifies the TextView in the
This gives a unique identity to the terms and conditions layout.
CheckBox. It helps the programmer access choosing interests 2. android:text
the CheckBox in the Java file. enabling optional settings It specifies the text to be displayed on the
2. android:text screen.
This is used to display the text label near 3. android:textColor
the CheckBox, such as “Music”, “Sports”, It is used to change the color of the text.
or “Reading”. 4. android:textSize
3. android:background It defines the size of the text. Usually sp
This sets the background of the CheckBox unit is used.
and improves the appearance of the 5. android:textStyle
control. It is used to apply styles like bold, italic, or
bold italic to the text.
Explain SQLite features 4. Lightweight Explain the steps to create and use 4. Insert values
SQLite is an open source relational SQLite is small in size and uses less SQLite database Create a ContentValues object and insert
database used in Android for storing, memory, so it is suitable for mobile In Android, SQLite is used to store column-value pairs using the insert()
managing, and retrieving persistent data. It devices. application data locally. The process of method.
is embedded in Android by default, so no 5. Supports SQL and transactions creating and using a SQLite database 5. Retrieve data using Cursor
separate database server is required. SQLite supports standard SQL statements involves a set of simple steps such as Use rawQuery() to retrieve records and
Because of its simple structure and and ACID transactions for safe data creating the database, creating a table, Cursor to move through the result set.
lightweight nature, SQLite is widely used operations. inserting values, retrieving data, and Methods like moveToFirst() and
in Android applications. closing the connection. moveToNext() are used.
Features of SQLite Steps to create and use SQLite database
1. Serverless database 1. Create SQLiteDatabase object
SQLite does not require a separate server First, create an object of SQLiteDatabase
process. It works directly within the to perform database operations.
application. 2. Open or create database
2. Zero configuration Use openOrCreateDatabase() method to
SQLite does not need installation, setup, or open an existing database or create a new
administration, so it is easy to use. database
3. Single file storage 3. Create table
The complete database is stored in a single Use execSQL() method to execute SQL
disk file, making it easy to manage and statements such as CREATE TABLE.
move.
Explain Activity life cycle 4. onPause() Explain JSON syntax rules Example
An Activity represents a single screen with This method is called when the activity is JSON stands for JavaScript Object {
a user interface in an Android application. partially hidden. At this stage, temporary Notation. It is a lightweight text-based "name":"John",
The Activity life cycle is the sequence of data should be saved. format used for storing and exchanging "age":30
callback methods through which an 5. onStop() and onDestroy() data. JSON is easy to read and write, and it }
activity passes from creation to onStop() is called when the activity follows simple syntax rules. Therefore, JSON syntax is simple,
destruction. It helps Android manage becomes completely hidden, and JSON syntax rules compact, and easy to understand, making
memory and app state properly. onDestroy() is the final method called 1. Data is in name/value pairs it useful for data interchange in
Main stages of Activity life cycle before the activity is removed. Each item in JSON is written as a key and applications.
1. onCreate() value. Example: "name":"John"
This is the first callback method. It is 2. Data is separated by commas
called when the activity is created. Here Multiple data items are separated by
the layout is loaded and controls are commas.
initialized. 3. Objects are enclosed in curly braces { }
2. onStart() A JSON object holds key-value pairs
This method is called when the activity inside braces.
becomes visible to the user 4. Arrays are enclosed in square brackets [
3. onResume() ]
This method is called when the activity A JSON array stores ordered values.
comes to the foreground and the user can 5. Values must be valid data types
interact with it. JSON values can be string, number, object,
array, boolean, or null.
Explain advantages of JSON over XML Use Explain Button and EditText EditText
JSON and XML are both used for data JSON is widely used in: Button and EditText are two important 4. Meaning
interchange, but JSON is considered better web applications user interface controls in Android. Button EditText is a subclass of TextView used to
in many modern applications because it is mobile applications is used to perform an action when clicked, enter and edit text.
lightweight and easier to process. JSON is server to app data exchange while EditText is used to accept input from 5. Important attributes
shorter, easier to read, and faster to parse Conclusion the user. Both are commonly used in android:id
than XML. Thus, JSON is preferred over XML forms, login pages, search screens, and android:text
Advantages of JSON over XML because it is lightweight, simple, faster, input-based applications. android:editable
1. JSON is shorter and easy to handle. Button android:background
JSON uses less text than XML, so it 1. Meaning android:inputType
makes data smaller and easier to transfer. A Button is a push button that performs an
2. Easier to read and write action when the user clicks it.
JSON format is simple and more 2. Important attributes
understandable to programmers. android:id
3. Supports arrays android:text
JSON supports arrays directly, while XML android:onClick
does not support them naturally. android:background
4. Faster parsing android:visibility
JSON can be parsed using standard 3. Uses
JavaScript functions like [Link](), submit forms
while XML needs an XML parser. move to next page
5. No end tags login
JSON does not use opening and closing save data
tags like XML, so it is less bulky.
Explain AVD and its components 4. Storage Area Explain custom toast alert 5. Display method
AVD stands for Android Virtual Device. It stores the settings, installed applications, A Toast is a small message displayed on After creating the toast layout, it is
It is used to create a virtual Android device and other user data. the screen for a short period of time. A displayed using the show() method.
on a computer for testing Android 5. SD Card Emulation custom toast alert is a modified toast Example use
applications. AVD helps developers run It provides virtual external storage for the message designed by the programmer Custom toast can be used to show:
apps in a virtual environment without device. using a custom layout. It is used when we login successful
using a real smartphone. It is very useful Uses want to show a message in a more error message
during application development and testing apps without real device attractive way than the default toast. record saved
debugging. Based on your notes and checking different Android versions Main points warning alert
repeated papers, this is an important debugging and development 1. Meaning of Toast
question. reducing cost of physical testing Toast is used to display short informational
Components of AVD devices messages to the user.
1. Hardware Profile 2. Custom Toast
It defines hardware features such as RAM, In custom toast, we design our own layout
screen size, camera, battery, and sensors. with text, color, or image.
2. System Image 3. Better appearance
It specifies the Android version installed in It makes the message more user friendly
the virtual device. and attractive.
3. Emulator Skin 4. Useful in apps
It gives the appearance, shape, and It is used for success messages, warning
dimensions of the virtual device. messages, login alerts, etc.
Explain any five attributes of What is custom toast alert? How can we Write short note on Emulators USB-connected physical device he
CheckBox implement it? State with example. An Android Emulator is a software tool emulator also supports many important
1. android:id In Android, a Toast is used to display that simulates Android devices on a hardware features of a real mobile device.
This attribute gives a unique identity to the information for a short period of time. It computer. It helps developers test These include ARMV5 CPU and MMU,
CheckBox. It helps the program refer to shows a message quickly on the screen applications on different Android devices 16-bit LCD display, keyboard support,
the control in Java code. and disappears automatically after a and API levels without needing a physical GSM modem with simulated SIM,
2. android:text specified duration. A custom toast alert is a device. The emulator provides almost all webcam camera, and accelerometer
This is used to display the label text near toast message shown using a custom the capabilities of a real Android device, sensors. Because of these features, the
the CheckBox, such as “Music”, “Sports”, layout instead of the default style. so it is very useful during application emulator gives a near real-device
or “Reading”. Steps to implement custom toast development. It can simulate Android environment for testing Android
3. android:background [Link] a custom XML layout phones, tablets, Wear OS devices, and applications.
This sets the background of the CheckBox Design a layout containing a TextView or Android TV devices. It can also simulate Thus, Android Emulator is a very useful
and improves its appearance in the layout. ImageView. incoming phone calls and text messages, development tool because it provides a
4. android:onClick 2. Inflate the layout in Java which helps in testing communication- virtual Android environment for testing
This specifies the method that should be Use LayoutInflater to load the XML file. based applications. Another important and debugging applications easily, quickly,
executed when the user clicks the 3. Create Toast object feature is location and network simulation, and economically.
CheckBox. Create a Toast object and set its duration. where the developer can specify the device
5. android:visibility 4. Set custom view location and test the application under
This controls whether the CheckBox is Attach the custom layout to the Toast different network speeds. The emulator
visible, invisible, or hidden from the using setView(). also supports screen rotation and hardware
screen. 5. Show the toast sensors like the accelerometer, which helps
Call the show() method to display the in testing responsive and sensor-based
message. applications. Testing on the emulator is
often faster and easier than testing on a.
Write the differences between JVM and application, while JVM has a constant What do you mean by transactions? transaction. Durability means that once a
DVM pool for every class. Finally, in DVM the What are the different methods transaction is committed, the changes
JVM and DVM are both virtual machines, executable type is usually APK, whereas available in transaction? remain permanent even if a crash occurs
but they differ in many ways. JVM (Java in JVM it is generally JAR. Thus, DVM is A transaction is a unit of work performed later.
Virtual Machine) is stack based, whereas specially designed for Android mobile against a database. It may include one or In SQLite, the main methods used in a
DVM (Dalvik Virtual Machine) is register devices, while JVM is used for general more database operations such as insert, transaction are beginTransaction(),
based. Because of its register-based Java applications on different platforms. update, or delete. Transactions are setTransactionSuccessful(), and
architecture, DVM is more suitable for important because they help maintain data endTransaction(). The beginTransaction()
low-memory mobile devices. JVM runs integrity and handle errors properly. method is used to start the transaction. The
.class files that contain Java bytecode, SQLite is a transactional database, and its setTransactionSuccessful() method is used
while DVM runs .dex files. In terms of transactions are ACID compliant. When to mark that all operations inside the
memory usage, DVM uses less memory, we create, update, or delete records in a transaction were completed successfully
so it is better suited for Android devices, database table, we are performing a and can be committed. The
whereas JVM generally uses more transaction. A transaction ensures that endTransaction() method is used to end the
memory. Another difference is in either all changes are applied successfully transaction, and it is usually placed inside
application handling: in DVM, each or none of them are applied. Transactions the finally block so that the transaction
Android application gets its own instance follow the ACID properties. Atomicity closes properly even if an error occurs.
of the virtual machine, while in JVM a means the whole transaction is completed
single instance can be shared by multiple fully or not at all. Consistency means the
applications. DVM supports only the transaction moves the database from one
Android operating system, whereas JVM valid state to another valid state. Isolation
supports multiple operating systems. means the changes made in one transaction
Also, DVM has a constant pool for every should not affect another unfinished