0% found this document useful (0 votes)
6 views10 pages

Mad CT Ut 2 QSTN Ans

The document provides an overview of various Android components and their attributes, including checkboxes, edit texts, and services. It explains the process of creating an API key for Google Maps, developing a date and time picker application, and designing an employee registration form. Additionally, it describes the Android service lifecycle and includes code snippets for practical implementation.

Uploaded by

gx59368
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Mad CT Ut 2 QSTN Ans

The document provides an overview of various Android components and their attributes, including checkboxes, edit texts, and services. It explains the process of creating an API key for Google Maps, developing a date and time picker application, and designing an employee registration form. Additionally, it describes the Android service lifecycle and includes code snippets for practical implementation.

Uploaded by

gx59368
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Question 1:

1) List any four attributes of check box.

Ans:

1)id 2)checked 3)gravity 4)text 5)text color 6)text size 7)text style 8)background 9)padding

2) Draw diagram of activity life cycle.

3) Name any four attributes of Edit Text control.

Ans:

android:id

android: gravity

android: text
android: hint

android: textColor

android: textSize

android: textStyle

android: background

4) Define SMS service in android application development.

Ans:

SMS

• In Android, you can use SmsManager API or devices Built-in SMS application to send SMS's

• Android SMS is stored in PDU (protocol description unit) format

• SmsManager class takes care of sending the SMS message.

• We just need to get an instance of it and send the SMS message.

• We need to add permission to SEND_SMS in the Android manifest file.

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

5) List different types of sensors used in android.

Ans:

The android platform supports three broad categories of sensors.

• Motion Sensors

These are used to measure acceleration forces and rotational forces along with three

axes.

• Environmental sensors

These are used to measure the environmental changes such as temperature, humidity etc.

• Position sensors

These are used to measure the physical position of device.


Q

1) Describe the process of getting the map API key.

Ans:

Creating API keys

The API key is a unique identifier that authenticates requests associated with your project marks

for usage and billing purposes. You must have at least one API key associated with your

project.

1. Browse the site on your browser. https://console. developers. google.com/project

2. Login with your google account.

3. Create a new project by clicking on Create Project option.

4. Add your project name and organization name in the fields present on the screen.

5. Now click on APIs and Services.

6. Enable APIs and services.

7. Select Google maps Android API

8. To create an API key for Maps click on Create credentials option and then select

the API key option.

Click on the API key option to generate your API key. After clicking on this option your

API key will be generated

2) Develop an android application for Date and Time Picker.

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"

tools:context=".MainActivity">

<EditText
android:layout_width="200dp"

android:layout_height="wrap_content"

android:id="@+id/in_time"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="SELECT TIME"

android:id="@+id/btn_time"

android:layout_below="@+id/in_time"/>

</RelativeLayout>

MainActivity.java

package com.example.myapplication.timepickerwithspinnermode;

import android.app.TimePickerDialog; import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TimePicker;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity implements

View.OnClickListener {

Button btnTimePicker;

EditText txtTime;

private int mHour, mMinute;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

btnTimePicker=(Button)findViewById(R.id.btn_time);
txtTime=(EditText)findViewById(R.id.in_time);

btnTimePicker.setOnClickListener(this);

@Override

public void onClick(View v) {

if (v == btnTimePicker) {

// Get Current Time

final Calendar c = Calendar.getInstance();

mHour = c.get(Calendar.HOUR_OF_DAY);

mMinute = c.get(Calendar.MINUTE);

// Launch Time Picker Dialog

TimePickerDialog timePickerDialog = new

TimePickerDialog(this, new

TimePickerDialog.OnTimeSetListener() { @Override

public void onTimeSet(TimePicker view, int hourOfDay,

int minute) {

txtTime.setText(hourOfDay + ":" + minute);

}, mHour, mMinute, false);

timePickerDialog.show();

3) Design a employee registration form using UI component.

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

<TextView

android:text="Employee Registration Form"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:id="@+id/textView"

android:gravity="center"

android:textSize="20dp"

android:textColor="#000000"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="ID"

android:id="@+id/editid"

android:layout_below="@+id/textView"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="Name"

android:id="@+id/editname"

android:layout_below="@+id/editid"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="Mobile No."

android:id="@+id/editmobile"

android:layout_below="@+id/editname"/>

<EditText
android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="Address"

android:lines="3"

android:id="@+id/editaddress"

android:layout_below="@+id/editmobile"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:hint="Pin Code"

android:id="@+id/editpincode"

android:layout_below="@+id/editaddress"/>

<Button

android:text="Submit Details"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/editpincode"

android:layout_centerHorizontal="true"

android:id="@+id/button" />

</RelativeLayout>

4) State syntax to create Text View and Image button with any two attributes of each.

Ans:

Text View:

Syntax :

<TextView

android:id="@+id/textView1"

android:layout_width="<width value>”

android:layout_height="<height_value>"

android:text="<text to be displayed>"/>

Attributes/Properties of TextView:
● id: Supply an identifier name of this view, to later retrieve it with View.findViewByID() or
Activity.findViewById()

● alpha: alpha property of the view as a value between 0 (entirely transparent) and 1(Completely
Opaque). [flag]

● auto link: Controls whether links such as urls and email addresses are automatically found and
converted to clickable links.[flag]

● gravity: The gravity attribute is an optional attribute which is used to control the alignment of
the text like left, right, center, top, bottom, center_vertical, center_horizontal etc

● text: text attribute is used to set the text in a text view. We can set the text in xml as well as in
the java class.

● textColor: textColor attribute is used to set the text color of a text view. Color value is in the
form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.

● textSize: textSize attribute is used to set the size of text of a text view. We can set the text size
in sp(scale independent pixel) or dp(density pixel).

● textStyle: textStyle attribute is used to set the text style of a text view. The possible text styles
are bold, italic and normal. If we need to use two or more styles for a text view then “|” operator
is used for that.

● background: background attribute is used to set the background of a text view. We can set a
color or a drawable in the background of a text view.

● padding: padding attribute is used to set the padding from left, right, top or bottom.

In above example code of background we also set the 10dp padding from all the

sides of text view.

ImageButton:

Syntax :

<ImageButton

android:id="@+id/imageButton"

android:layout_width="<width value>"

android:layout_height="<height value>"

app:srcCompat="<image source from drawable folder "/>

Attributes/Properties of ImageButton:

● id: id is an attribute used to uniquely identify a image button. Below is the example code in
which we set the id of a image button.

● src: src is an attribute used to set a source file of image or you can say image in your image
button to make your layout look attractive.

● background: background attribute is used to set the background of an image button. We can
set a color or a drawable in the background of a Button.
● padding: padding attribute is used to set the padding from left, right, top or bottom of the
ImageButton.

5) Describe Android service life cycle along with diagram.

Ans:

A service is an application component which runs without direst interaction with the user in the
background.

Services are used for repetitive and potentially long running operations, i.e., Internet downloads,
checking for new data, data processing, updating content providers and the like.

Service can either be started or bound we just need to call either startService() or bindService() from
any of our android components. Based on how our service was started it will either be “started” or
“bound”.

Service Lifecycle

1. Started

a. A service is started when an application component, such as an activity, starts it by calling


startService().
b. Now the service can run in the background indefinitely, even if the component that started it is
destroyed.

2. Bound

a. A service is bound when an application component binds to it by calling bindService().

b. A bound service offers a client-server interface that allows components to interact with the
service, send requests, get results, and even do so across processes with InterProcess
Communication (IPC).

c. Like any other components service also has callback methods. These will be invoked while the
service is running to inform the application of its state. Implementing these in our custom service
would help you in performing the right operation in the right state.

d.There is always only a single instance of service running in the app. If you are calling startService()
for a single service multiple times in our application it just invokes the onStartCommand() on that
service. Neither is the service restarted multiple times nor are its multiple instances created

1. onCreate():

This is the first callback which will be invoked when any component starts the service. If the same
service is called again while it is still running this method wont be invoked. Ideally one time setup
and intializing should be done in this callback.

2. onStartCommand() /startSetvice()

This callback is invoked when service is started by any component by calling startService(). It basically
indicates that the service has started and can now run indefinetly.

3. onBind()

To provide binding for a service, you must implement the onBind() callback method. This method
returns an IBinder object that defines the programming interface that clients can use to interact with
the service.

4. onUnbind()

This is invoked when all the clients are disconnected from the service.

5. onRebind()

This is invoked when new clients are connected to the service. It is called after onRebind

6. onDestroy()

This is a final clean up call from the system. This is invoked just before the service is being destroyed.

You might also like