0% found this document useful (0 votes)
10 views

qbmad

The document provides an overview of various Android concepts including Text to Speech, service and activity life cycles, multimedia framework, and UI components like TextView, Button, and ListView. It also includes code examples for creating Android applications using LinearLayout and RelativeLayout, as well as implementing a date-time picker. Additionally, it explains intents, sensors, and methods for extracting values from a cursor in Android development.

Uploaded by

ARYAN MOHADE
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)
10 views

qbmad

The document provides an overview of various Android concepts including Text to Speech, service and activity life cycles, multimedia framework, and UI components like TextView, Button, and ListView. It also includes code examples for creating Android applications using LinearLayout and RelativeLayout, as well as implementing a date-time picker. Additionally, it explains intents, sensors, and methods for extracting values from a cursor in Android development.

Uploaded by

ARYAN MOHADE
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/ 29

1.Explain Text to Speech in android.

Ans.
2. Explain service life cycle.
3. Explain multimedia framework
4. Explain activity life cycle
Q.5.Enlist the use of following UI components. a. Text View b. Toggle Button c. Button d.Radio Button e.
Custom Toast alert f. Image Button g. Radio Group Button. h.Scroll View

a. TextView

Used to display text to the user. It is a non-editable view, often used for labels, headings, or any
text content.

b. ToggleButton

Used to switch between two states – ON and OFF. It's like a switch that shows its current state.

c. Button

A clickable UI element used to perform an action when clicked by the user (e.g., submit a form,
go to next screen).

d. RadioButton

Used to select one option from a set. Usually used inside a RadioGroup to ensure only one
option is selected.

e. Custom Toast Alert

Used to show a brief message in a customized design (layout, color, icon, etc.). Helpful in
giving feedback in a stylish way.

f. ImageButton

A button with an image/icon instead of text. Useful for actions like camera, settings, back, etc.

g. RadioGroup

A container for RadioButtons. It ensures only one RadioButton is selected at a time among its
children.

h. ScrollView

A layout that allows the user to scroll the content vertically. Useful when UI content is larger
than the screen size.
Q.6 Develop an android application using linear layout

Ans.

Activitymain.xml

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

<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">

<TextView

android:id="@+id/textView"

android:text="Enter your name:"

android:textSize="18sp"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:id="@+id/editTextName"

android:hint="Your name"

android:layout_width="match_parent"

android:layout_height="wrap_content" />
<Button

android:id="@+id/buttonGreet"

android:text="Say Hello"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

</LinearLayout>

Mainactivity.java

package com.example.linearapp;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText editTextName;

Button buttonGreet;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
editTextName = findViewById(R.id.editTextName);

buttonGreet = findViewById(R.id.buttonGreet);

buttonGreet.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String name = editTextName.getText().toString();

Toast.makeText(MainActivity.this, "Hello " + name + "!",


Toast.LENGTH_SHORT).show();

});

Q.7 Develop an android application using relative layout.

Activity_main.xml

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="16dp">

<TextView

android:id="@+id/textView"

android:text="Enter Name:"
android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:id="@+id/editText"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/textView"

android:layout_marginTop="10dp"

android:hint="Type here" />

<Button

android:id="@+id/button"

android:text="Click Me"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/editText"

android:layout_marginTop="10dp"

android:layout_centerHorizontal="true" />

</RelativeLayout>

Main_activity.java

package com.example.relativelayoutdemo;

import android.os.Bundle;

import android.view.View;
import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText editText;

Button button;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

editText = findViewById(R.id.editText);

button = findViewById(R.id.button);

button.setOnClickListener(view -> {

String name = editText.getText().toString();

Toast.makeText(this, "Hello " + name, Toast.LENGTH_SHORT).show();

});

}
Q.8Develop an application for date-time picker.

Ans.

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

<LinearLayout

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:padding="16dp">

<Button

android:id="@+id/btnPickDate"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Pick Date" />

<Button

android:id="@+id/btnPickTime"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Pick Time"

android:layout_marginTop="10dp" />

<TextView
android:id="@+id/tvResult"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Selected Date & Time"

android:textSize="18sp"

android:layout_marginTop="20dp"/>

</LinearLayout>

Activitymain.java

package com.example.datetimepicker;

import android.app.DatePickerDialog;

import android.app.TimePickerDialog;

import android.os.Bundle;

import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {

Button btnPickDate, btnPickTime;

TextView tvResult;

int year, month, day, hour, minute;

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

btnPickDate = findViewById(R.id.btnPickDate);

btnPickTime = findViewById(R.id.btnPickTime);

tvResult = findViewById(R.id.tvResult);

Calendar calendar = Calendar.getInstance();

btnPickDate.setOnClickListener(v -> {

year = calendar.get(Calendar.YEAR);

month = calendar.get(Calendar.MONTH);

day = calendar.get(Calendar.DAY_OF_MONTH);

new DatePickerDialog(this, (view, y, m, d) -> {

tvResult.setText("Date: " + d + "/" + (m+1) + "/" + y);

}, year, month, day).show();

});

btnPickTime.setOnClickListener(v -> {

hour = calendar.get(Calendar.HOUR_OF_DAY);

minute = calendar.get(Calendar.MINUTE);

new TimePickerDialog(this, (view, h, m) -> {

String currentText = tvResult.getText().toString();


tvResult.setText(currentText + "\nTime: " + h + ":" + String.format("%02d", m));

}, hour, minute, true).show();

});

}
Q.9Explain Android Directory Structure.

Q.10Write short note on 1. Bluetooth 2. Camera 3.Animation

Ans.
✅ 1. Bluetooth in Android

 Bluetooth allows Android devices to wirelessly communicate with other Bluetooth-


enabled devices.
 It is used for data transfer, audio streaming, file sharing, etc.
 Android provides the BluetoothAdapter class to manage Bluetooth functionalities like
enabling/disabling, device discovery, and connecting.
 Permissions like BLUETOOTH and BLUETOOTH_ADMIN are required in the manifest.

✅ 2. Camera in Android

 Android provides Camera API and CameraX API to capture photos and videos.
 You can either:
o Use the built-in camera app with an Intent
(MediaStore.ACTION_IMAGE_CAPTURE)
o Or build a custom camera using the camera APIs.
 Requires permissions:
CAMERA and optionally WRITE_EXTERNAL_STORAGE.

✅ 3. Animation in Android

 Animations are used to enhance user experience by adding visual effects to UI


components.
 Types of animations:
o Property Animation – Used for modern smooth effects (scale, rotate, fade).
o View Animation – Basic 2D animations (translate, rotate, scale, alpha).
o Drawable Animation – Frame-by-frame animation using images.
 Animations can be defined in XML or handled programmatically in Java/Kotlin.

Q.11 what is intent and intent filter in android

An Intent is a messaging object used to request an action from another component (like Activity,
Service, or BroadcastReceiver).
� Uses:

 To start a new activity


 To start a service
 To send a broadcast
 To share data between apps or components

An Intent is a messaging object used to request an action from another component (like Activity,
Service, or BroadcastReceiver).

� Uses:

 To start a new activity


 To start a service
 To send a broadcast
 To share data between apps or components

Q.12 explain sensor in android

✅ 5-Line Theory: Sensor in Android

1. Sensors in Android detect physical changes like motion, light, position, etc.
2. Android uses SensorManager to access sensors.
3. Sensors can be motion, environmental, or position based.
4. You must use SensorEventListener to get sensor data.
5. Common sensors include Accelerometer, Gyroscope, and Light Sensor.

✅ Simple XML Layout (activity_main.xml)


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

<TextView android:id="@+id/tvSensor" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Sensor Data"
android:textSize="18sp"/>
</LinearLayout>

✅ Simple Java Code (MainActivity.java)


import android.hardware.*;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity implements
SensorEventListener {

SensorManager sm;
Sensor accelerometer;
TextView tvSensor;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvSensor = findViewById(R.id.tvSensor);
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
accelerometer = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sm.registerListener(this, accelerometer,
SensorManager.SENSOR_DELAY_NORMAL);
}

@Override
public void onSensorChanged(SensorEvent event) {
tvSensor.setText("X: " + event.values[0] +
"\nY: " + event.values[1] +
"\nZ: " + event.values[2]);
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
}

Q13. How to extract value from cursor in Android

n Android, when you query a database (like SQLite), the result is returned in a Cursor object.
You can use it to extract values row-by-row.

✅ Steps to Extract Value from Cursor:

1. Move cursor to the first row using cursor.moveToFirst().


2. Use cursor.getString(), getInt(), etc., with column index or column name to
extract data.

✅ Example Code:
java
CopyEdit
Cursor cursor = db.rawQuery("SELECT name, age FROM users", null);
if (cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));

Log.d("User Info", "Name: " + name + ", Age: " + age);


} while (cursor.moveToNext());
}
cursor.close(); // Always close the cursor after use

✅ Common Methods to Extract Data:

Method Use for extracting


getString(index) String values
getInt(index) Integer values
getFloat(index) Float values
getColumnIndex(name) Get column index by name

Q,14Explain any Four components of Android UI design with is attributes. Sure Aryan! Here's a
3-line simple theory for any four Android UI components, along with their commonly used
attributes:

✅ 1. TextView

Theory (3 lines):

 Displays text on the screen.


 Used to show static or dynamic data.
 It is non-clickable by default.

Common Attributes:

 android:text → Sets the text


 android:textSize → Sets the size of the text
 android:textColor → Sets the color of the text

✅ 2. Button

Theory (3 lines):

 Used to perform an action when clicked.


 Can display text or an icon.
 Triggers events via setOnClickListener().

Common Attributes:

 android:text → Button label


 android:onClick → Calls a method on click
 android:background → Sets background color or image

✅ 3. EditText

Theory (3 lines):

 Allows the user to input text.


 It is an editable version of TextView.
 Useful in forms, login pages, and data input.

Common Attributes:

 android:hint → Placeholder text


 android:inputType → Type of input (text, number, password)
 android:maxLength → Maximum characters allowed

✅ 4. ImageView

Theory (3 lines):

 Displays images in the layout.


 Can load images from resources or the internet.
 Often used for icons, banners, logos, etc.

Common Attributes:

 android:src → Sets image source


 android:scaleType → Controls image scaling
 android:contentDescription → Adds accessibility text

Q.15Explain the use of List View and grid view


Sure Aryan! Here's a simple 6-line theory and example for both ListView and GridView in
Android:

✅ ListView

� 6-Line Theory:

1. ListView is used to display a vertical scrollable list of items.


2. It can show data from arrays, database, or APIs.
3. Each item appears in a single row.
4. Requires an Adapter to bind data (like ArrayAdapter or CustomAdapter).
5. Commonly used for menus, messages, or contact lists.
6. Efficient for long lists using view recycling.

� Simple Example:

XML (activity_main.xml):

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Java (MainActivity.java):

ListView listView = findViewById(R.id.listView);


String[] items = {"Apple", "Banana", "Mango"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, items);
listView.setAdapter(adapter);

✅ GridView

� 6-Line Theory:

1. GridView is used to show items in a grid (rows and columns) layout.


2. Good for displaying images or icons.
3. Each cell/item is evenly spaced.
4. Also needs an Adapter to bind data.
5. Useful in galleries, dashboards, product displays, etc.
6. You can set the number of columns using android:numColumns.
� Simple Example:

XML (activity_main.xml):

<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" />

Java (MainActivity.java):

GridView gridView = findViewById(R.id.gridView);


String[] fruits = {"Apple", "Banana", "Mango", "Orange"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, fruits);
gridView.setAdapter(adapter);

Let me know if you want a custom layout example too (with images or custom design)!

Q.16explain contend provider in android

✅ Content Provider in Android – Simple Explanation

A Content Provider is a component in Android that manages access to a structured set of


data and allows data sharing between different apps.

✅ Key Points:

1. It acts as a bridge between apps and data.


2. Data can be stored in SQLite database, files, or other storage.
3. Other apps access the data using URI (Uniform Resource Identifier).
4. Access is controlled via methods like:
o query() – to read data
o insert() – to insert data
o update() – to modify data
o delete() – to remove data
5. You must declare a ContentProvider in the AndroidManifest.xml.
6. Common system providers include Contacts, Call Logs, SMS, Media (Images/Videos).

✅ Use Case Example:


 Your app wants to read contact names from the phone:

Cursor cursor = getContentResolver().query(


ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

if (cursor.moveToFirst()) {
String name =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME
));
}
cursor.close();

✅ Why Use It?

 To share data securely between apps.


 To allow inter-app communication with proper permissions

q.17 Explain android components with its syntax.

Ans.

Sure Aryan! Here's a simple explanation of the 4 main Android components with their short
theory and syntax:

✅ 1. Activity

� Theory:

 Represents a single screen with a user interface.


 It is the entry point for user interaction.
 Examples: Login screen, Home screen.

� Syntax:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

✅ 2. Service
� Theory:

 A Service runs in the background, without UI.


 Used for tasks like playing music, downloading files, etc.

� Syntax:
public class MyService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Background work here
return START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
return null;
}
}

✅ 3. BroadcastReceiver

� Theory:

 It listens for system-wide broadcast messages.


 Example: Battery low, incoming SMS, network change.

� Syntax:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Broadcast Received!",
Toast.LENGTH_SHORT).show();
}
}

✅ 4. ContentProvider

� Theory:

 Manages and shares data between apps securely.


 Other apps access its data via URI.

� Syntax:
public class MyProvider extends ContentProvider {
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
return null;
}

// Also override insert(), update(), delete(), getType() as needed


}

You might also like