Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Question Bank ch no 4,5,6

1. List all attributes to develop a simple checkbox (2M)


In Android, CheckBox is a type of two state button either unchecked or
checked in Android.
1.id
2. checked
3. gravity
4. text
5. textColor
6. textSize
7. textStyle
8. background.

2. Write the syntax for Intent-Filter tag. (2M)

Intent Filter are the components which decide the behavior of an intent. Intent
filters specify the type of intents that an Activity, service or Broadcast receiver can
respond to. It declares the functionality of its parent component (i.e. activity,
services or broadcast receiver). It declares the capability of any activity or services
or a broadcast receiver.

syntax of Intent Filters:


Intent filter is declared inside Manifest file for an Activity.

<!--Here Name of Activity is .MainActivity, image of icon name stored in drawabl


e folder, label present inside string name is label-->
<!--If anything is different please customize the code according to your app-->
<activity android:name=".MainActivity">
<intent-filter android:icon="@drawable/icon"
android:label="@string/label"
>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

3. Define services in Android operating system.

Ans.:

In Android, a service is a component that runs in the background and performs long-
running operations or tasks without requiring any user interaction. Services can perform
various tasks like playing music, downloading data, or processing data in the
background.

Services are often used in mobile application development to provide a seamless user
experience by allowing the app to continue running and performing tasks in the
background while the user interacts with other apps or even while the device is locked
or the app is not in the foreground.

There are two types of services in Android:

1. Started Services: A started service is a service that is started explicitly by calling


the startService() method. Once started, it can continue to run even if the
component that started it is destroyed. A started service can run indefinitely in
the background until it is stopped explicitly by calling the stopService() method.
2. Bound Services: A bound service is a service that is bound to a component by
calling the bindService() method. Once bound, a component can interact with the
service by calling its methods. The service will continue to run as long as it is
bound to at least one component. When all components unbind from the service,
the service is destroyed.

Services can also run in the same process as the app or in a separate process to improve
performance and reliability. Additionally, services can be configured to run as a
foreground service, which provides a notification to the user and ensures that the
service is not killed by the system when resources are low.

Overall, services provide a powerful way for developers to perform long-running


operations and provide a seamless user experience in their mobile applications.

4. Enlist the steps to publish the Android application

Ans.:
Sure, here are the steps to publish an Android application on the Google Play Store:

1. Create a Developer Account: To publish an Android application on the Google Play


Store, you must first create a developer account on the Google Play Console.

2. Create an Application: Create an Android application by developing it in Android Studio


or another development environment.

3. Prepare your App for Release: Before publishing the app, ensure that it is properly
tested, optimized, and free of any bugs.

4. Generate a Signed APK: Generate a signed APK file of your app from Android Studio,
which is a digitally signed package containing the application's code and resources.

5. Create a Listing on the Google Play Store: Sign in to the Google Play Console, create a
new listing for your app, and provide all the required information such as app title,
description, screenshots, and videos.

6. Upload the APK: Upload the signed APK to the Google Play Console and fill in the
additional required details.

7. Submit for Review: Once you have uploaded the app, submit it for review to ensure that it
meets the Google Play Store guidelines and policies.

8. Wait for Approval: Wait for Google to approve your app. This process can take several
hours or even days, depending on the complexity of your application.

9. Publish Your App: Once approved, your app will be published on the Google Play Store,
and it will be available for download by users.
5. Explain the activity life cycle. (4M)

Ans.:

An activity is the single screen in android. It is like window or frame of Java.

The activity lifecycle refers to the different states an activity goes through from its creation to its
destruction.
Method Description

onCreate called when activity is first created.

onStart called when activity is becoming visible to the user.

onResume called when activity will start interacting with the user.

onPause called when activity is not visible to the user.

onStop called when activity is no longer visible to the user.

onRestart called after your activity is stopped, prior to start.

onDestroy called before the activity is destroyed.

6. Explain Date and Time picker with its methods. (4M)

Ans.:
In Android, Date and Time picker are UI components that allow users to select a specific
date and time. These components are commonly used in applications that involve scheduling,
reminders, alarms, and other time-related functions.

DatePicker and TimePicker classes are used to create date and time picker dialogs
respectively. These classes provide various methods to customize the appearance and
behavior of the pickers. Here are some of the commonly used methods for DatePicker and
TimePicker classes:

DatePicker Methods

1. init(int year, int monthOfYear, int dayOfMonth,


DatePicker.OnDateChangedListener listener) - Initializes the date picker with a
specified year, month, and day. The OnDateChangedListener is used to handle date
change events.

2. updateDate(int year, int month, int dayOfMonth) - Updates the date picker with a
specified year, month, and day.

3. setMaxDate(long maxDate) - Sets the maximum date that can be selected in the date
picker.
4. setMinDate(long minDate) - Sets the minimum date that can be selected in the date
picker.

5. setCalendarViewShown(boolean shown) - Shows or hides the calendar view in the date


picker.

TimePicker Methods

1. setIs24HourView(boolean is24HourView) - Sets whether the time picker is displayed in


24-hour format or not.

2. setCurrentHour(Integer currentHour) - Sets the current hour value for the time picker.

3. setCurrentMinute(Integer currentMinute) - Sets the current minute value for the time
picker.

4. setOnTimeChangedListener(TimePicker.OnTimeChangedListener listener) - Sets


the listener that will handle time change events in the time picker.

5. setMinuteInterval(int minuteInterval) - Sets the interval between minutes that can be


selected in the time picker.

These methods can be used to create customized date and time picker dialogs based on the
specific requirements of the application.

7. Write a program to display circular progress bar. (4M)

Ans.:
Here is an example program to display a circular progress bar and a button in an Android
app:

activity_main.xml:

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

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

tools:context=".MainActivity">

<!-- Circular Progress Bar -->

<ProgressBar

android:id="@+id/progress_circular"

style="?android:attr/progressBarStyle"

android:layout_width="100dp"

android:layout_height="100dp"

android:indeterminate="true"

android:visibility="visible"

android:layout_centerInParent="true"/>

<!-- Button to Hide the Progress Bar -->

<Button

android:id="@+id/btn_hide_progress"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/progress_circular"

android:layout_centerHorizontal="true"

android:text="Hide Progress Bar" />

MainActivity.java:

import android.os.Bundle;
import android.view.View;

import android.widget.Button;

import android.widget.ProgressBar;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

ProgressBar progressBarCircular;

Button btnHideProgress;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize the Progress Bar

progressBarCircular = findViewById(R.id.progress_circular);

// Initialize the Button to Hide the Progress Bar

btnHideProgress = findViewById(R.id.btn_hide_progress);

btnHideProgress.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// Hide the Progress Bar

progressBarCircular.setVisibility(View.INVISIBLE);

});

AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.progressbar">

<uses-permission android:name="android.permission.INTERNET" />

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

This program displays a circular progress bar in the center of the screen and a button below
it. When the button is clicked, the progress bar is hidden.

8. List sensors in Android and explain any one in detail.

Ans.:

9. Explain zoom control (IN / OUT) with the help of an example

Ans.: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

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

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<!--Adding the image view-->

<ImageView

android:id="@+id/image_View"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:scaleType="fitXY"

android:src="@drawable/indiamap" />

<!--Adding the Zoom Controls

within the relative layout-->

<ZoomControls

android:id="@+id/zoom_controls"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_margin="10dp" />

</RelativeLayout>

MainActivity.java

// Java code to implement the zoom controls


import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;

import android.os.Bundle;

import android.view.MotionEvent;

import android.view.View;

import android.widget.ImageView;

import android.widget.ZoomControls;

public class MainActivity extends AppCompatActivity {

ImageView imageView;

ZoomControls zoomControls;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

imageView=findViewById(R.id.image_View);

zoomControls=findViewById(R.id.zoom_controls);

zoomControls.setBackgroundColor(Color.BLACK);

zoomControls.show();

// onTouch listener function when the image is clicked

imageView.setOnTouchListener(

new View.OnTouchListener() {

@Override

public boolean onTouch(View view, MotionEvent


motionEvent) {

zoomControls.show();
return false;

);

// This function will be automatically called out,when

// zoom in button is being pressed

zoomControls.setOnZoomInClickListener(

new View.OnClickListener() {

@Override

public void onClick(View view) {

float x=imageView.getScaleX();

float y=imageView.getScaleY();

// setting the new scale

imageView.setScaleX((float)(x+0.5f));

imageView.setScaleY((float)(y+0.5f));

zoomControls.hide();

);

// This function will be called when

// zoom out button is pressed

zoomControls.setOnZoomOutClickListener(

new View.OnClickListener() {
@Override

public void onClick(View view) {

float x=imageView.getScaleX();

float y=imageView.getScaleY();

if(x==1 && y==1)

// the scale will remain same,since

// it is maximum possible zoom out

imageView.setScaleX((float)(x));

imageView.setScaleY((float)(y));

zoomControls.hide();

else

// setting the new scale

imageView.setScaleX((float)(x-0.5f));

imageView.setScaleY((float)(y-0.5f));

// hiding the zoom controls

zoomControls.hide();

);

}
10.Write a program to capture an image using camera and display it. (4M)

Ans.: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:padding="40dp"
android:orientation="horizontal"
tools:context=".MainActivity">

<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CAMERA"
android:textSize="20dp"
android:gravity="center"/>

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="81dp"
android:src="@drawable/rose"/>

<Button
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="TAKE PHOTO" />

</RelativeLayout>
MainActivity.java
package com.example.ifediv;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {

Button bl;
ImageView imageView;
int CAMERA_REQUEST = 1;

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

bl = findViewById(R.id.photo);
imageView = findViewById(R.id.image);

bl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_REQUEST);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {


Bitmap image = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}

11.Develop a program to send an email.

Ans.:
Here is a sample program to send an email in Android:

First, we need to add the following permission in the AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />

Then, in the MainActivity.java file, we can add the following code:

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button sendEmailButton = findViewById(R.id.send_email_button);

sendEmailButton.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {

sendEmail();

});

private void sendEmail() {

String recipient = "recipient@example.com";

String subject = "Test email";

String body = "This is a test email sent from my Android app.";

Intent intent = new Intent(Intent.ACTION_SENDTO);

intent.setData(Uri.parse("mailto:")); // only email apps should handle this

intent.putExtra(Intent.EXTRA_EMAIL, new String[] {recipient});

intent.putExtra(Intent.EXTRA_SUBJECT, subject);

intent.putExtra(Intent.EXTRA_TEXT, body);

if (intent.resolveActivity(getPackageManager()) != null) {

startActivity(intent);

In the above code, we define a `sendEmail()` method that creates an Intent to send an email.
We specify the recipient, subject, and body of the email, and then use the
`Intent.ACTION_SENDTO` action to launch an email app that can handle the email intent.
Finally, we add a button to the layout file (activity_main.xml) and set a click listener to call
the `sendEmail()` method when the button is clicked.

12.Develop an application to store student details like roll no, name,


branch, marks, percentage and retrieve student information using roll
no. in SQLite databases.

Ans.:

13.Write a program to locate user’s current location. (Write ONLY .java


and manifest file)

Ans.:
Here's an example program to locate user's current location in Android:

MainActivity.java

import android.Manifest;

import android.content.pm.PackageManager;

import android.location.Location;

import android.os.Bundle;

import android.widget.TextView;

import android.widget.Toast;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.ActivityCompat;

import androidx.core.content.ContextCompat;

import com.google.android.gms.location.FusedLocationProviderClient;

import com.google.android.gms.location.LocationServices;
public class MainActivity extends AppCompatActivity {

private static final int PERMISSIONS_REQUEST_LOCATION = 1;

private FusedLocationProviderClient fusedLocationClient;

private TextView locationText;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

locationText = findViewById(R.id.location_text);

if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)

!= PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION},

PERMISSIONS_REQUEST_LOCATION);

} else {

getLocation();

private void getLocation() {


fusedLocationClient.getLastLocation()

.addOnSuccessListener(this, new OnSuccessListener<Location>() {

@Override

public void onSuccess(Location location) {

if (location != null) {

String latitude = String.valueOf(location.getLatitude());

String longitude = String.valueOf(location.getLongitude());

locationText.setText("Latitude: " + latitude + ", Longitude: " + longitude);

} else {

Toast.makeText(MainActivity.this, "Unable to get location.",


Toast.LENGTH_SHORT).show();

});

@Override

public void onRequestPermissionsResult(int requestCode, @NonNull String[]


permissions, @NonNull int[] grantResults) {

super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == PERMISSIONS_REQUEST_LOCATION) {

if (grantResults.length > 0 && grantResults[0] ==


PackageManager.PERMISSION_GRANTED) {

getLocation();

} else {
Toast.makeText(this, "Location permission denied.",
Toast.LENGTH_SHORT).show();

```

activity_main.xml

```xml

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

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

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".MainActivity">

<TextView

android:id="@+id/location_text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Location:"

android:textSize="20sp"
android:gravity="center" />

</LinearLayout>

```

AndroidManifest.xml

```xml

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

package="com.example.currentlocation">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application

android:name=".MyApplication"

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/Theme.CurrentLocation">

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

14.Explain any four UI Components of Android application.

Ans.:
Here are four commonly used UI components in Android applications:

1. TextView: This is a basic UI component that displays text on the screen. It can be used to
display a label or description for other UI elements or to display dynamic text generated
by the application.
2. ImageView: This component is used to display images in an Android application. It
supports a variety of image formats and provides options for scaling, cropping, and tinting
the image.
3. EditText: This is a component that allows the user to enter text or numbers. It can be used
for various types of input, such as usernames, passwords, search queries, and more.
4. Button: This component provides a clickable button that the user can use to trigger an
action or submit a form. It can be customized with text, images, and various styles to match
the application's design.

These UI components are often used in combination with each other and with other UI elements
to create a functional and visually appealing user interface in Android applications.

You might also like