0% found this document useful (0 votes)
30 views9 pages

Part A: 2020 March

Bachelor of Computer Application, Semester 6, Android
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)
30 views9 pages

Part A: 2020 March

Bachelor of Computer Application, Semester 6, Android
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/ 9

Part A

Module 4 : Android

2020 March

8. How do SQLite provide database features with a


compressed library?
SQLite is a lightweight relational database management system that provides efficient,
reliable, and scalable data storage for Android apps. It achieves this by using a compressed
library that implements most of the SQL92 standard, making it faster and more compact than
other relational databases. This allows apps to store and manage data locally on the device,
even with limited storage and processing power.

9. What is the function of the content value instance?


ContentValues is a class in Android that stores a set of key-value pairs representing column
names and their values in a database table. It is commonly used in ContentProvider
operations to insert, update or delete data from a database. The ContentValues instance
provides a convenient and type-safe way to manage database operations in Android apps.

10. Write the importance of Transaction in SQLite database.


Transactions in SQLite databases are essential for ensuring data integrity and consistency,
especially in multi-user environments. They provide a way to group database operations into
atomic units that either complete entirely or are rolled back if an error occurs. This helps to
prevent data corruption and ensure the accuracy and reliability of database operations.
Transactions are crucial for complex database operations and ensuring the data is handled
reliably in Android apps.

2021 April

8. Why can't we say that SQLite is the replacement of Oracle,


but it is the replacement of fopen()?
SQLite is not a replacement for Oracle because they serve different purposes. SQLite is a
lightweight database engine that is embedded in Android for storing and retrieving data
locally on the device, whereas Oracle is a relational database management system that is
used for enterprise-level data processing. However, SQLite can be considered a
replacement for fopen() because it provides a structured way to store and access data,
whereas fopen() only provides a way to open and manipulate files.
9. Explain any two methods that are used to iterate through the
cursor.
Two common methods used to iterate through a Cursor in Android are:

● moveToFirst() method is used to move the cursor to the first row of the result set,
and returns a boolean value indicating whether the move was successful or not. This
method is commonly used to retrieve the first row of data from the cursor.
● moveToLast() method is used to move the cursor to the last row of the result set,
and returns a boolean value indicating whether the move was successful or not. This
method is commonly used to retrieve the last row of data from the cursor.

10. Write a function to move records in cursor.


To move records in a cursor in Android, you can use the moveToPosition() method. This
method takes an integer parameter indicating the position of the desired record within the
cursor, starting at position 0 for the first record.

For example, to move to the third record in a cursor:


if (cursor.moveToPosition(2)) {
// Process data for the third record
}

This code snippet moves the cursor to position 2 (i.e., the third record) and checks if the
move was successful before processing the data.

2022 April

8. Which feature of SQLite signifies storage for Mobile


Application Development?
SQLite is a self-contained, serverless, zero-configuration, transactional database engine
that provides local storage for mobile application development. It is embedded in Android
and allows developers to store, retrieve, and manage data in a structured way. SQLite
provides a lightweight and efficient solution for mobile devices, making it a popular choice for
Android application development.

9. What are the parameters used in the insert() method?


insert() method in Android is used to insert a new row in a SQLite database. It takes
three parameters - the table name, a null column hack, and a ContentValues object that
contains the column name/value pairs for the row to be inserted.
The first parameter is a string that specifies the name of the table where the row will be
inserted. The second parameter is used when the values of all the columns are empty or
null. The third parameter is a ContentValues object that contains the column name/value
pairs for the row to be inserted.

10. Write the syntax of query() method.


The syntax of the query() method in Android is as follows:
Cursor query(String table, String[] columns, String selection, String[]
selectionArgs, String groupBy, String having, String orderBy)

This method is used to execute a SELECT query on the specified table in the SQLite
database. It returns a Cursor object that contains the result set of the query.
Part B
Module 4 : Android

2020 March

19. Explain different packages imported for Wi-fi activity.


There are several packages imported for Wi-Fi activity in Android, each with its own set of
functionalities. Some of the most commonly used packages are:

● android.net.wifi package provides classes to interact with Wi-Fi hardware,


scan networks, connect to a network, manage settings, and work with Wi-Fi Direct.
● android.net.wifi.p2p package provides classes for Wi-Fi Direct to discover
nearby devices, create groups, and establish connections for peer-to-peer
communication in apps like file sharing or multiplayer gaming.
● android.net.wifi.aware package provides classes for Wi-Fi Aware to discover
nearby devices, establish connections, and exchange data without an access point.

Developers can use these packages to build Wi-Fi enabled apps on Android, whether they
are simple or complex, as they offer a range of tools and necessary functionality for
connecting to Wi-Fi networks or utilizing advanced Wi-Fi technologies like Wi-Fi Direct or Wi-
Fi Aware.

20. Write a java and xml code to save the details of student to
sqlite table student(regno, name, address).
Java code:
public class AddStudentActivity extends AppCompatActivity {
EditText regnoText, nameText, addressText;
Button addButton;
SQLiteDatabase db;

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

regnoText = findViewById(R.id.regno);
nameText = findViewById(R.id.name);
addressText = findViewById(R.id.address);
addButton = findViewById(R.id.addBtn);

db = openOrCreateDatabase("studentsDB", MODE_PRIVATE, null);


addButton.setOnClickListener(v -> {
String regno = regnoText.getText().toString();
String name = nameText.getText().toString();
String address = addressText.getText().toString();

String insertQuery = "INSERT INTO student(regno, name,


address) VALUES(?,?,?)";
db.execSQL(insertQuery, new String[]{regno, name, address});

Toast.makeText(this, "Student details added",


Toast.LENGTH_SHORT).show();

regnoText.setText("");
nameText.setText("");
addressText.setText("");
});
}
}

XML Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<EditText
android:id="@+id/regno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Registration Number"/>

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"/>

<EditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Address"/>
<Button
android:id="@+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>

</LinearLayout>

2021 April

19. How do we setup SQLite database connection?


To set up a SQLite database connection in Android, first create a subclass of
SQLiteOpenHelper. Then override the onCreate() and onUpgrade() methods to
create the database and handle any upgrades. After that, create an instance of the
SQLiteOpenHelper class, passing in the context, database name, and version number,
and call the getWritableDatabase() or getReadableDatabase() method to obtain a
SQLiteDatabase object that can be used to perform database operations. Finally, use the
SQLiteDatabase object to perform operations like inserting, updating, and querying data.

When setting up a SQLite database connection, it is important to properly handle errors,


such as the database being locked, and to close the database connection when it is no
longer needed. Additionally, it is recommended to use constants for column names and table
names, to avoid typos and make it easier to refactor the code in the future.

20. Explain sending SMS with an example.


Sending SMS in Android can be achieved using the SMS Manager class. To send an SMS,
we need to create an instance of the SMS Manager class and call its sendTextMessage()
method.

Example:
// Get instance of SMS Manager
SmsManager smsManager = SmsManager.getDefault();

// Define recipient's phone number and message text


String phoneNumber = "1234567890";
String message = "Hello from Android App!";

// Send SMS
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
Here, we first obtain the instance of the SMS Manager using its getDefault() method.
Then, we define the recipient's phone number and message text. Finally, we call the
sendTextMessage() method, passing in the recipient's phone number, message text, and
other optional parameters.

Note: To send SMS, the sender needs to add the SEND_SMS permission to sender’s
AndroidManifest.xml file.

2022 April

19. What is the need for BroadcastReceiver while scanning wi-


fi?
BroadcastReceiver is used to receive system-wide broadcasts or intents. When scanning
Wi-Fi, the BroadcastReceiver is required to receive Wi-Fi scan results through the intent.
The Wi-Fi scan results contain the list of available Wi-Fi access points, their signal strengths,
and other relevant information.

The BroadcastReceiver allows the application to register for specific intent filters and receive
relevant broadcasts. When the Wi-Fi scan results are ready, the system broadcasts the
intent, which triggers the onReceive() method of the registered BroadcastReceiver. The
application can then extract the relevant information from the intent and perform any
necessary actions, such as displaying the available Wi-Fi access points in a list or map view.

20. Write a java and xml code to delete the details of students
from sqlite table student(regno, name, address) whose regno is
given.
First, create a layout file (delete_student_layout.xml) to input the registration number:
<EditText
android:id="@+id/regno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Registration Number"
/>

<Button
android:id="@+id/deleteBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete"
/>

Next, create a Java activity class (DeleteStudentActivity.java) to handle the deletion process:
public class DeleteStudentActivity extends AppCompatActivity {
EditText regnoText;
Button deleteButton;
SQLiteDatabase db;

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

regnoText = findViewById(R.id.regno);
deleteButton = findViewById(R.id.deleteBtn);

db = openOrCreateDatabase("studentsDB", MODE_PRIVATE, null);

deleteButton.setOnClickListener(v -> {
String regno = regnoText.getText().toString();
db.execSQL("DELETE FROM student WHERE regno = ?", new
String[]{regno});
Toast.makeText(this, "Student details deleted",
Toast.LENGTH_SHORT).show();
});
}
}

In the above code, we first initialize the views and get the database instance. Then we set a
click listener for the delete button, where we retrieve the registration number entered by the
user, execute the delete query, and display a toast message to confirm the deletion.
Part C
Module 4 : Android

2020 March
(No questions asked)

2021 April
(No questions asked)

2022 April
(No questions asked)

You might also like