Mad CT Ut 2 QSTN Ans
Mad CT Ut 2 QSTN Ans
Ans:
1)id 2)checked 3)gravity 4)text 5)text color 6)text size 7)text style 8)background 9)padding
Ans:
android:id
android: gravity
android: text
android: hint
android: textColor
android: textSize
android: textStyle
android: background
Ans:
SMS
• In Android, you can use SmsManager API or devices Built-in SMS application to send SMS's
Ans:
• 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
Ans:
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.
4. Add your project name and organization name in the fields present on the screen.
8. To create an API key for Maps click on Create credentials option and then select
Click on the API key option to generate your API key. After clicking on this option your
Ans:
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">
<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.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TimePicker;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Calendar;
View.OnClickListener {
Button btnTimePicker;
EditText txtTime;
@Override
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
if (v == btnTimePicker) {
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
TimePickerDialog(this, new
TimePickerDialog.OnTimeSetListener() { @Override
int minute) {
timePickerDialog.show();
Ans:
activity_main.xml
<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: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
ImageButton:
Syntax :
<ImageButton
android:id="@+id/imageButton"
android:layout_width="<width value>"
android:layout_height="<height value>"
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.
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
2. Bound
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.