qbmad
qbmad
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.
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
<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: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;
EditText editTextName;
Button buttonGreet;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextName = findViewById(R.id.editTextName);
buttonGreet = findViewById(R.id.buttonGreet);
buttonGreet.setOnClickListener(new View.OnClickListener() {
@Override
});
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"
<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;
EditText editText;
Button button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editText);
button = findViewById(R.id.button);
button.setOnClickListener(view -> {
});
}
Q.8Develop an application for date-time picker.
Ans.
<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"
<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: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;
TextView tvResult;
@Override
setContentView(R.layout.activity_main);
btnPickDate = findViewById(R.id.btnPickDate);
btnPickTime = findViewById(R.id.btnPickTime);
tvResult = findViewById(R.id.tvResult);
btnPickDate.setOnClickListener(v -> {
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
});
btnPickTime.setOnClickListener(v -> {
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
});
}
Q.9Explain Android Directory Structure.
Ans.
✅ 1. Bluetooth in Android
✅ 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
An Intent is a messaging object used to request an action from another component (like Activity,
Service, or BroadcastReceiver).
� Uses:
An Intent is a messaging object used to request an action from another component (like Activity,
Service, or BroadcastReceiver).
� Uses:
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.
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) {}
}
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.
✅ 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"));
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):
Common Attributes:
✅ 2. Button
Theory (3 lines):
Common Attributes:
✅ 3. EditText
Theory (3 lines):
Common Attributes:
✅ 4. ImageView
Theory (3 lines):
Common Attributes:
✅ ListView
� 6-Line Theory:
� Simple Example:
XML (activity_main.xml):
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Java (MainActivity.java):
✅ GridView
� 6-Line Theory:
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):
Let me know if you want a custom layout example too (with images or custom design)!
✅ Key Points:
if (cursor.moveToFirst()) {
String name =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME
));
}
cursor.close();
Ans.
Sure Aryan! Here's a simple explanation of the 4 main Android components with their short
theory and syntax:
✅ 1. Activity
� Theory:
� Syntax:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
✅ 2. Service
� Theory:
� 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:
� 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:
� 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;
}