Professional Documents
Culture Documents
Question Bank
Question Bank
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.
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.
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.
Ans.:
Sure, here are the steps to publish an Android application on the Google Play Store:
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.:
The activity lifecycle refers to the different states an activity goes through from its creation to its
destruction.
Method Description
onResume called when activity will start interacting with the user.
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
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.
TimePicker Methods
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.
These methods can be used to create customized date and time picker dialogs based on the
specific requirements of the application.
Ans.:
Here is an example program to display a circular progress bar and a button in an Android
app:
activity_main.xml:
<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">
<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
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"
MainActivity.java:
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import androidx.appcompat.app.AppCompatActivity;
ProgressBar progressBarCircular;
Button btnHideProgress;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBarCircular = findViewById(R.id.progress_circular);
btnHideProgress = findViewById(R.id.btn_hide_progress);
btnHideProgress.setOnClickListener(new View.OnClickListener() {
@Override
progressBarCircular.setVisibility(View.INVISIBLE);
});
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.progressbar">
<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>
</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.
Ans.:
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">
<ImageView
android:id="@+id/image_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/indiamap" />
<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
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ZoomControls;
ImageView imageView;
ZoomControls zoomControls;
@Override
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();
imageView.setOnTouchListener(
new View.OnTouchListener() {
@Override
zoomControls.show();
return false;
);
zoomControls.setOnZoomInClickListener(
new View.OnClickListener() {
@Override
float x=imageView.getScaleX();
float y=imageView.getScaleY();
imageView.setScaleX((float)(x+0.5f));
imageView.setScaleY((float)(y+0.5f));
zoomControls.hide();
);
zoomControls.setOnZoomOutClickListener(
new View.OnClickListener() {
@Override
float x=imageView.getScaleX();
float y=imageView.getScaleY();
imageView.setScaleX((float)(x));
imageView.setScaleY((float)(y));
zoomControls.hide();
else
imageView.setScaleX((float)(x-0.5f));
imageView.setScaleY((float)(y-0.5f));
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;
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);
Ans.:
Here is a sample program to send an email in Android:
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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendEmailButton.setOnClickListener(new View.OnClickListener() {
@Override
sendEmail();
});
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.
Ans.:
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 {
@Override
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();
@Override
if (location != null) {
} else {
});
@Override
if (requestCode == PERMISSIONS_REQUEST_LOCATION) {
getLocation();
} else {
Toast.makeText(this, "Location permission denied.",
Toast.LENGTH_SHORT).show();
```
activity_main.xml
```xml
<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">
<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>
</intent-filter>
</activity>
</application>
</manifest>
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.