AADK_answers
AADK_answers
1. (a) Create a class for Employee, write a user defined function to accept the attributes
of employee and display the attribute in kotlin.
// Define the Employee class
class Employee(
){
fun displayInfo() {
println("Name: $name")
println("ID: $id")
println("Department: $department")
println("Position: $position")
println("Salary: $salary")
fun main() {
emp.displayInfo()
(b) Explain setter and getter function with suitable example in Kotlin. What do you
mean by ternary operator? Explain how if statement is used as ternary operator in
Kotlin? (imp)
In this code, name is a property of the Employee class. The get() and set(value) functions are the
getter and setter for this property, respectively. The field keyword is a special keyword that
refers to the property itself.
Ternary Operator: A ternary operator is a shorthand way of writing an if-else statement. It’s
called “ternary” because it takes three operands: a condition, a result for true, and a result
for false.
However, Kotlin does not have a traditional ternary operator like condition ? true : false.
Instead, you can use the if statement as an expression, which serves a similar purpose.
Here’s an example:
fun main() {
val number = 10
val result = if (number > 0) "Positive" else "Non-positive"
println(result) // Prints "Positive"
}
In this code, if (number > 0) "Positive" else "Non-positive" is similar to a ternary operation.
If the condition number > 0 is true, it returns "Positive"; otherwise, it returns "Non-
positive". The result is then stored in the result variable. This is how you can use if as a
ternary operator in Kotlin.
2. (a) Explain with suitable example interface in Kotlin?
In Kotlin, an interface is a common aspect that classes can choose to implement. An interface
can contain declarations of abstract methods and properties as well as method implementations.
Here’s an example:
interface Drivable {
fun drive()
println("Driving a car.")
println("Riding a bike.")
}
fun main() {
In this code:
Car and Bike are classes that implement the Drivable interface, meaning they provide their own
implementations of the drive() method.
In the main() function, we create instances of Car and Bike, both referred to by the Drivable
interface type. When we call drive() on these instances, the appropriate method is called based
on the actual type of the object.
This is a basic example. In real-world applications, interfaces can be used to achieve complex
functionality and enable polymorphism.
Interoperability with Java: Kotlin is fully interoperable with Java, which means that you can
use all existing Java libraries and frameworks, and your Kotlin code can coexist with Java code
in the same project.
Null Safety: Kotlin aims to eliminate the risk of null references from code, also known as the
the Billion Dollar Mistake. Kotlin’s type system is designed to eliminate
NullPointerException’s from our code.
Extension Functions: Kotlin provides the ability to extend a class with new functionality
without having to inherit from the class. This is done via special declarations called extensions.
Coroutines: Kotlin has built-in support for coroutines, which makes asynchronous
programming easier and more intuitive.
Smart Casts: The Kotlin compiler tracks your logic and auto-casts types if possible, which
eliminates the need for explicit casting.
Default Arguments and Named Parameters: Kotlin allows you to specify default values for
function parameters and also lets you call functions using named arguments for better
readability.
Data Classes: Kotlin provides a concise syntax for creating classes used to hold data/state,
known as data classes.
Immutability: Kotlin encourages the use of immutable data which makes your code more
predictable and easier to reason about.
Scripting: Besides being an object-oriented language, Kotlin also supports scripting. You can
write scripts in Kotlin and execute them directly without any boilerplate code.
3. (a) Write a Kotlin function to display all the prime numbers between 1 to 100.
fun main() {
for (i in 2..100) {
for (j in 2 until i) {
if (i % j == 0) {
isPrime = false
break
if (isPrime) {
println(i)
In Kotlin, interfaces and classes serve different purposes and have distinct characteristics. Here
are the key differences between interfaces and classes:
Purpose:
Interface: An interface in Kotlin defines a set of methods and properties that a class must
implement. It specifies a contract that classes can adhere to, without providing the
implementation details.
Class: A class in Kotlin is a blueprint for creating objects. It can contain properties,
methods, constructors, and other members that define the behavior and state of objects.
Implementation:
Interface: Interfaces only declare method signatures and properties without providing the
implementation. Classes that implement an interface must provide concrete implementations for
all the methods and properties defined in the interface.
Class: Classes can provide concrete implementations for methods and properties. They
can also inherit from other classes or implement interfaces.
Inheritance:
Interface: Interfaces can inherit from other interfaces using the : symbol. A class can
implement multiple interfaces, allowing for multiple inheritance of behavior.
Class: Classes can inherit from other classes using the : symbol. However, Kotlin does
not support multiple inheritance for classes (except for inheriting from multiple interfaces),
meaning a class can only inherit from one superclass.
Usage:
Interface: Interfaces are often used to define contracts for implementing classes,
especially in cases where multiple classes need to exhibit similar behavior but may have
different implementations.
Class: Classes are used to create objects and define their behavior. They encapsulate data
and behavior into a single unit, providing a way to model real-world entities and concepts.
Abstract Members:
Interface: All members (methods and properties) of an interface are abstract by default.
They do not have a body and must be implemented by classes that implement the interface.
Class: Classes can have both abstract and concrete members. Abstract members in a class
are declared using the abstract keyword and must be implemented by subclasses.
(b) What are the different types of variables in Kotlin? Explain with examples.
In Kotlin, variables can be classified into different types based on their mutability, scope, and
initialization. Here are the main types of variables in Kotlin:
Example:
val pi = 3.14
Example:
var count = 0
Nullable Variables:
Variables that can hold a null value in addition to their regular type.
Declared using the nullable type syntax with ? after the type.
Example:
Used for non-null mutable variables that are initialized later, typically in the constructor or a
setup method.
They must be initialized before being accessed to avoid lateinit property not initialized errors.
Example:
Constants (const):
Variables whose values are known at compile time and cannot be changed during runtime.
Declared using the const modifier at the top level or inside an object.
Example:
Local Variables:
return sum
5. (a) What are data classes in Kotlin? Explain with a proper example.
In Kotlin, data classes are a concise way to declare classes that are primarily used for holding
data. These classes automatically generate several standard methods such as equals(),
hashCode(), toString(), and copy() based on the properties defined in the class. Data classes can
significantly reduce boilerplate code when working with classes that primarily serve as data
containers. Here's an example to illustrate data classes in Kotlin:
fun main() {
// Create an instance of Person using the data class constructor
val person1 = Person("John Doe", 30)
val person2 = Person("Jane Smith", 25)
(b) Explain the concept of null safety in Kotlin with suitable example.
In Kotlin, null safety is a built-in feature that helps eliminate the risk of null references, also
known as the “The Billion Dollar Mistake”. Kotlin’s type system is designed to distinguish
nullable references from non-nullable ones.
Non-Nullable Types: By default, all types are non-nullable, which means you cannot assign
null to a variable of a non-nullable type. For example:
In this code, nonNullableString is a non-nullable String, so trying to assign null to it will cause a
compile error.
Nullable Types: If you want to allow null values, you can declare a variable as nullable by
appending a ? to the type. For example:
In this code, nullableString is a nullable String, so you can assign null to it without any issues.
Safe Calls (?.) and the Elvis Operator (?:): When you’re dealing with nullable types, you
need to handle the possibility of null values. You can use safe calls (?.) to only call a method or
access a property if the receiver is non-null. If the receiver is null, the whole expression will be
null. You can also use the Elvis operator (?:) to provide a default value when the receiver is null.
For example:
In this code, length will be null if nullableString is null, and safeLength will be 0 if
nullableString is null.
In Kotlin, constructors are used to initialize the properties of a class when an instance of the
class is created. There are two types of constructors in Kotlin: primary constructors and
secondary constructors.
1. Primary Constructor:
The primary constructor is declared in the class header as part of the class declaration. It is
responsible for initializing the properties of the class. Here's an example of a class with a
primary constructor:
fun main() {
// Creating an instance of Person using the primary constructor
val person = Person("John Doe", 30)
fun main() {
// Creating an instance of Person using the secondary constructor
val person = Person("Jane Smith", 25)
The when keyword in Kotlin is a powerful replacement for the traditional switch statement
found in many other programming languages. It provides a concise and expressive way to write
conditional branches based on the value of an expression. Here's how when works in Kotlin:
Basic Syntax:
The basic syntax of when is as follows:
when (expression) {
value1 -> action1
value2 -> action2
...
else -> defaultAction
}
expression: The value or expression to be evaluated.
value1, value2, etc.: Possible values or conditions that expression can match.
action1, action2, etc.: Actions to be performed if the corresponding value matches expression.
else: Optional, provides a default action if none of the values match.
Example:
Here's an example of using when to check the value of a variable and perform different actions
based on its value:
fun describeNumber(number: Int) {
when (number) {
1 -> println("One")
2 -> println("Two")
3 -> println("Three")
else -> println("Other")
}
}
fun main() {
describeNumber(2) // Outputs: Two
describeNumber(5) // Outputs: Other
}
In this example:
Additional Features:
Multiple Conditions:
when (number) {
1, 2 -> println("One or Two")
3, 4 -> println("Three or Four")
else -> println("Other")
}
Ranges:
when (number) {
in 1..5 -> println("Number is between 1 and 5")
!in 10..20 -> println("Number is not between 10 and 20")
else -> println("Other")
}
Type Checks:
when (obj) {
is String -> println("Object is a String")
is Int -> println("Object is an Int")
else -> println("Other")
}
Smart Casts:
when (obj) {
is String -> println(obj.length) // obj is automatically cast to String
is Int -> println(obj * 2) // obj is automatically cast to Int
else -> println("Other")
}
when in Kotlin is versatile and can handle a wide range of conditions and scenarios, making it
a flexible and powerful tool for writing conditional logic in a concise and readable manner.
UNIT – 2
1. (a) Explain the activity life cycle and callback functions in Android Application.
1. onCreate(): Called when the activity is first created. It is used for initialization, such as
setting up UI components and data structures.
2. onStart(): Called when the activity becomes visible to the user. This is where you can
start animations or perform UI updates.
3. onResume(): Called when the activity is ready to interact with the user. You can start
tasks that should continue while the activity is in the foreground.
4. onPause(): Called when the activity is partially obscured by another activity. Use this
method to pause ongoing tasks or save user data.
5. onStop(): Called when the activity is no longer visible to the user. Release resources or
stop processes that are no longer needed.
6. onDestroy(): Called when the activity is about to be destroyed. Clean up any resources or
unregister listeners.
The core building blocks of an Android application are fundamental components that work
together to create a functional and interactive user experience. These building blocks include:
1. Activities: Activities represent the UI (User Interface) of an application. Each screen in
an Android app is typically represented by an activity. Activities can contain layouts, user
interface elements, and respond to user interactions.
2. Services: Services are components that run in the background to perform long-running
operations or handle tasks without a user interface. They can play music, download files,
or perform other tasks that don't require user interaction.
3. Broadcast Receivers: Broadcast Receivers respond to system-wide broadcast
announcements, such as when the device's battery is low or when a message is received.
They can perform actions based on these broadcasts, such as displaying a notification.
4. Content Providers: Content Providers manage access to a structured set of data. They
allow applications to share data with other apps or access data from other apps. Content
Providers are often used to access data from the device's built-in databases or other
external sources.
5. Fragments: Fragments represent reusable portions of a UI in an activity. They allow for
more modular and flexible UI designs, especially for larger screens like tablets where
multiple UI components may be displayed simultaneously.
6. Intents: Intents are messages that allow components to request functionality from other
components within the application or even from external applications. They can be used
to start activities, services, or broadcast actions.
7. Manifest File: The AndroidManifest.xml file describes essential information about the
application to the Android system. It includes details such as the app's package name,
permissions required, declared components (activities, services, etc.), and other
configuration settings.
(b) Write the code for dynamics textview and provide action to the textview in android?
MainActivity.kt
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
3. Write an android programming to change the layout background color using radio
button(use minimum 3 buttons).
Activity_main.xml
<RadioButton
android:id="@+id/radioButtonRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red" />
<RadioButton
android:id="@+id/radioButtonGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Green" />
<RadioButton
android:id="@+id/radioButtonBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue" />
<Button
android:id="@+id/buttonApply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apply Color" />
</LinearLayout>
MainActivity.kt
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.RadioButton
import android.widget.RadioGroup
buttonApply.setOnClickListener {
when {
radioButtonRed.isChecked -> changeBackgroundColor(Color.RED)
radioButtonGreen.isChecked -> changeBackgroundColor(Color.GREEN)
radioButtonBlue.isChecked -> changeBackgroundColor(Color.BLUE)
}
}
}
Login.kt
package com.example.sectionb
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.example.sectionb.databinding.ActivityLoginBinding
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="120dp"
android:layout_marginEnd="55dp"
android:text="Enter User Id"
app:layout_constraintEnd_toStartOf="@+id/editEmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="112dp"
android:layout_marginEnd="13dp"
android:ems="10"
android:inputType="textEmailAddress"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="47dp"
android:layout_marginEnd="50dp"
android:text="Enter Password"
app:layout_constraintEnd_toStartOf="@+id/editPw"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<EditText
android:id="@+id/editPw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/editEmail"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="72dp"
android:layout_marginEnd="162dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editPw" />
</androidx.constraintlayout.widget.ConstraintLayout>
Home.kt
package com.example.sectionb
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.sectionb.databinding.ActivityHomeBinding
import com.example.sectionb.databinding.ActivityLoginBinding
<TextView
android:id="@+id/tvHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="128dp"
android:layout_marginTop="161dp"
android:layout_marginEnd="226dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Dynamic views in Android are used when you want to create UI elements on the fly or modify
the properties of UI elements after they’ve been drawn on the screen. They are particularly
useful when you don’t want to have repeating XML code.
RecyclerView: It’s a ViewGroup that contains the views corresponding to your data. It’s a view
itself, so you add RecyclerView to your layout the way you would add any other UI element.
ViewHolder: Each individual element in the list is defined by a view holder object. When the
view holder is created, it doesn’t have any data associated with it. After the view holder is
created, the RecyclerView binds it to its data. You define the view holder by extending
RecyclerView.ViewHolder.
Adapter: The RecyclerView requests views, and binds the views to their data, by calling
methods in the adapter. You define the adapter by extending RecyclerView.Adapter.
LayoutManager: The layout manager arranges the individual elements in your list. You can use
one of the layout managers provided by the RecyclerView library, or you can define your own.
Adding Views Dynamically: Dynamic Views are created when we don’t want to have repeating
XML code. In this case, we create a separate layout and inflate them inside a LinearLayout.
Storing Data: After creating the views, we can store the user data in an ArrayList and then
display them.
Animations: To move, reveal, or hide views within the current layout, you can use the property
animation system provided by the android.animation package.
UNIT – 3
1. Create an android application to create 3 buttons with label red,green and blue. On
clicking any button, a textview “Welcome” will be displayed in the specified colour.
MainActivity.kt
btnRed.setOnClickListener { changeTextColor(Color.RED) }
btnGreen.setOnClickListener { changeTextColor(Color.GREEN) }
btnBlue.setOnClickListener { changeTextColor(Color.BLUE) }
activity_main.xml:
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"
android:orientation="vertical" tools:context=".MainActivity">
<Button android:id="@+id/btnRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red" />
<Button android:id="@+id/btnGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Green" />
<Button android:id="@+id/btnBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue" />
<TextView
android:id="@+id/textViewWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome" android:textSize="24sp"
/>
</LinearLayout>
LinearLayout RelativeLayout
Syntax: Syntax:
<LinearLayout> <RelativeLayout>
<!–Views, widgets–> <!–Views, Widgets–>
</LinearLayout> </RelativeLayout>
Example: In various Apps,
LinearLayout is mainly
applicable in the SignUp screen Example: In Google Play Store, when we
where Name, Email, Phone open the app, the games, books, movies,
Number, Submit, etc. are and App’s sections all are arranges in
arranged in a linear fashion. Relative Layout Fashion.
LinearLayout RelativeLayout
### LinearLayout:
**Example:**
```xml
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Text" />
</LinearLayout>
```
In this example, the TextViews are arranged vertically one below the other within the
LinearLayout.
### RelativeLayout:
**Example:**
```xml
<RelativeLayout
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"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_below="@id/button1"
android:layout_alignParentRight="true" />
</RelativeLayout>
```
In this example, Button 1 is positioned at the top-left corner of the RelativeLayout, and Button 2
is positioned below Button 1 and aligned to the parent's right edge.
UNIT – 4
First, create a shared preferences file for your app. Name it uniquely using your app’s package
name (e.g., com.example.myapp_preferences).
SharedPreferences sharedPreferences =
getSharedPreferences("com.example.myapp_preferences", Context.MODE_PRIVATE);
Storing Data:
You can save data using the SharedPreferences.Editor class. For example, let’s save a user’s
username:
editor.putString("username", "myuser123");
Retrieving Data:
Use Cases:
SQLiteOpenHelper:
This class helps in managing database creation and version management.
You need to subclass SQLiteOpenHelper and implement the onCreate() and onUpgrade()
methods.
I.SQLiteDatabase:
It provides methods for executing SQL statements, such as query(), insert(), update(), and
delete().
II.SQLiteOpenHelper Subclass:
onCreate(): Called when the database is created for the first time. You should create your
database
tables here.
onUpgrade(): Called when the database needs to be upgraded. You should handle schema
changes here.
III.Context:
IV.Cursor:
It provides methods to move through the result set and retrieve data from each row.
V.ContentValues:
ContentValues is a key-value pair container used to insert or update values into the database.
You populate ContentValues with column-value pairs and pass it to SQLiteDatabase insert() or
update() methods.
VI.SQL Statements:
You use SQL statements to interact with the database, such as CREATE TABLE, SELECT,
INSERT,
You can execute raw SQL statements using SQLiteDatabase's execSQL() method.
VII.Error Handling:
Handle exceptions that may occur during database operations, such as SQLiteException.
3. Explain the process of storing and retrieve data from SQLite database.
- Override the onCreate() method to create database tables and the onUpgrade() method to
handle
schema changes.
- If the database does not exist, SQLiteOpenHelper's onCreate() method will be called to
create it.
3. **Prepare Data**:
- Data can be organized in ContentValues objects, where each key-value pair represents a
columnvalue mapping.
4. **Insert Data**:
- Pass the table name, nullColumnHack (optional), and ContentValues object to the insert()
method.
1. **Query Data**:
- Specify the table name, columns to retrieve, selection criteria (optional), selection arguments
(optional), group by clause (optional), having clause (optional), order by clause (optional), and
limit
clause (optional).
2. **Process Cursor**:
- The query() method returns a Cursor object that points to the result set.
3. **Retrieve Data**:
- Use Cursor's getter methods (e.g., getInt(), getString()) to retrieve data from each row of the
result set.
- Close the Cursor when you're done processing data to release associated resources.
- Close the database connection using SQLiteDatabase's close() method when it's no longer
needed.
depending on the type of data and the requirements of your application. Here are some
common
methods:
1. **Shared Preferences**:
- It's suitable for storing small amounts of primitive data types like integers, booleans, floats,
and
strings.
- SharedPreferences provides a way to save and retrieve data across app launches.
- This method is commonly used for storing user preferences, settings, and other lightweight
data.
2. **Internal Storage**:
- Internal Storage is private storage space allocated to each app by the Android system.
- You can write data to files in internal storage using FileOutputStream or other file I/O
classes.
- This method is suitable for storing sensitive data or files that are only accessible to your app.
- Internal storage is not accessible to users or other apps unless the device is rooted.\
3. **External Storage**:
- External Storage provides a shared storage space that's accessible by all apps and users.
- You can write data to external storage using standard file I/O operations.
- External storage includes the device's external storage (e.g., SD card) and any USB mass
storage
- It provides a structured and efficient way to store and retrieve structured data.
- SQLite databases are suitable for storing larger amounts of structured data, such as user
- You can interact with SQLite databases using the SQLiteDatabase class provided by the
Android
SDK.
- It provides an abstraction layer over SQLite databases, making it easier to work with
databases
in Android apps.
- Room simplifies tasks like defining database schemas, executing queries, and observing
database changes.
- It's suitable for apps that require complex data models or need to perform advanced database
operations.
6. **Network Storage**:
- You can also persist data on remote servers or cloud storage services.
- This method allows you to synchronize data across multiple devices and provides scalability
and
accessibility.
- Common approaches include using RESTful APIs, Firebase Realtime Database, Google
Cloud
Storing and retrieving data from a Firebase Realtime Database in an Android application
involves
1. **Set Up Firebase**:
- Add the Firebase SDK to your Android project by following the setup instructions provided
by
Firebase.
- Configure your Android app to use Firebase services by adding the necessary configuration
files.
FirebaseDatabase.getInstance().getReference() method.
3. **Prepare Data**:
4. **Write Data**:
- Use the DatabaseReference object obtained in step 2 to write data to the database.
- Call methods like setValue() or updateChildren() to store data at the desired location in the
database.
1. **Read Data**:
Add the Google Maps API key to your Android project by following the setup instructions
provided by
Google.
Enable the necessary permissions and dependencies in your app's manifest file.
Design the user interface layout for your app, including text fields for entering source and
destination
Use the Places API to enable autocomplete functionality for the source and destination text
fields.
Implement logic to fetch latitude and longitude coordinates for the entered source and
destination
Use the Directions API to request navigation directions between the source and destination
coordinates.
Parse the response from the Directions API to extract the route details (such as polyline points).
Display the navigation route on a Google Map using PolylineOptions to draw polylines
between the
Here's a simplified example code snippet to demonstrate how you can implement navigation
using
// Use Places API to fetch place IDs for source and destination
// Use Geocoding API to fetch latitude and longitude coordinates for source and destination
// Use Directions API to fetch navigation route between source and destination
drawRouteOnMap(route)