Question Bank Unit Test 2
Question Bank Unit Test 2
In android, we can send SMS from our android application in two ways either by using
SMSManager API or Intents based on our requirements.
If we use SMSManager API, it will directly send SMS from our application. In case if we use Intent with proper
action (ACTION_VIEW), it will invoke a built-in SMS app to send SMS from our application.
There are two types of Intents: Implict :Establishes connection between application to application
Explicit:between activity to activity.
Intent Filer: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.
There are following three elements in an intent filter:
1. Action :what an activity is going to do.
2. Data :allows to pass the data
3. Category: decides behavior or nature of an Intent.
In android, Broadcast Receiver is a component which will allow android system or other apps to deliver events to the
app like sending a low battery message or screen turned off message to the app.
In android, Content Provider will act as a central repository to store the applications data in one place and make that
data available for different applications to access whenever it’s required.
query() - It receives a request from the client. By using arguments it will get a data from requested table and return
the data as a Cursor object.
insert() - This method will insert a new row into our content provider and it will return the content URI for newly
inserted row.
update() - This method will update an existing rows in our content provider and it return the number of rows updated.
delete() - This method will delete the rows in our content provider and it return the
number of rows deleted.
getType() - This method will return the MIME type of data to given content URI.
onCreate() - This method will initialize our provider. The android system will call this
method immediately after it creates our provider.
Fragment:Part of the Activity also known as sub-activity. An activity can contain multiple of fragments
Service:Android service is a component that is used to perform operations on the
background such as playing music, handle network transactions, interacting content
providers etc. It is an android component with UI
There can be two forms of a service.The lifecycle of service can follow two different paths:
started or bound.
1. Started
2. Bound
1) Started Service
A service is started when component (like activity) calls startService() method, now it runs in the background
indefinitely. It is stopped by stopService() method. The service can stop itself by calling the stopSelf() method.
2) Bound Service
A service is bound when another component (e.g. client) calls bindService() method. The client can unbind the
service by calling the unbindService() method.
The service cannot be stopped until all clients unbind the service.
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.
onStartCommand()
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.
onBind()
This is invoked when any component starts the service by calling onBind.
onUnbind()
This is invoked when all the clients are disconnected from the service.
onRebind()
This is invoked when new clients are connected to the service. It is called after onUnbind
onDestroy()
This is a final clean up call from the system. This is invoked just before the service is being destroyed. Could be very
useful to cleanup any resources such as threads, registered listeners, or receivers.