Chapter 5 Mad
Chapter 5 Mad
INTENT ACTION
ANDROID
SYSTEM
USES OF INTENT IN
ADNROID
1.Starting an activity:
An Activity represents a single screen in an app.
You can start a new instance of an Activity by
passing an Intent to startActivity().
The Intent describes the activity to start and
carries any necessary data.
For example, if you are having two activities
namely LoginActivity and MainActivity then,
you can start the MainActivity by clicking the
login button present on the LoginActivity.
By using the startActivity(), you can start the
desired Activity using the Intents.
2. Starting a Service
A Service is a component that performs
operations in the background without a user
interface.
You can start a service to perform a one-time
operation (such as downloading a file) by
passing an Intent to startService().
The Intent describes the service to start and
carries any necessary data.
3.Delivering a broadcast
A broadcast is a message that is received
by the application from the system.
The system delivers various broadcasts for
system events, such as when the system
boots up or the device starts charging.
You can deliver a broadcast to other apps
by passing
an Intent to sendBroadcast() or
sendOrderedBroadcast().
Intent Types
Whenever you open an Android application, then you see some UI over
your screen. That screen is called an Activity. It is the basic component
of Android and whenever you are opening an application, then you are
opening some activity.
For example, when you open your Gmail application, then you see
your emails on your screen. Those emails are present in an Activity. If
you open some particular email, then that email will be opened in some
other Activity.
An activity lifecycle shows all the states with transitioning from one
state to the next state
The Activity lifecycle consists of
7 methods:
onCreate() : It is called when an activity is first created.
When a user opens the app then some Activity is
created. You have to implement this method in every
activity because, inside this method, all the necessary
components of your activity will be initialized. Here the
initialization of your application's UI is done.
onStart(): This method is called when an activity
becomes visible to the user. When all the initialization is
done by the onCreate() method, then this method is
called.
onResume(): It is called just before the user starts
interacting with the application. Most of the core
functionalities of the app are implemented in this
method.
onPause(): It is called when the activity is paused i.e. it is
mostly called when you press the back or home button of
your Android device. It is an indication that the user is
leaving the activity and starting some other activity.
onStop(): It is called when the activity is no longer visible
to the user. If you are starting a new activity, or some
existing activity is entering into onResume() state, then the
current activity will not be visible to the user and is stopped.
onRestart(): It is called when the activity in the stopped
state is about to start again. By doing so, the state of the
activity from the time it was stopped will be restored.
onDestroy(): It is called when the activity is totally
destroyed i.e. when you clear the application stack then
onDestroy() will be called and all the states of the activity
will be destroyed.
Broadcast Lifecycle
Broadcast intents
<prefix>://<authority>/
<data_type>/<id>
Create Content Provider
Each fragment has its own life cycle methods that is affected
by activity life cycle because fragments are embedded in
activity.
Motion sensors:-
These sensors measure acceleration forces and
rotational forces along three axes. This category includes
accelerometers, gravity sensors, gyroscopes, and
rotational vector sensors.
Environmental sensors:-
These sensors measure various environmental
parameters, such as medium air temperature and
pressure, illumination, and humidity. This category
includes barometers, photometers, and thermometers.
Position sensors:-
These sensors measure the physical position of a device.
This category includes orientation sensors and
magnetometers.
Sensor Framework
You can access available sensors and acquire raw sensor
data in your app with the Android sensor framework.
The sensor framework, part of the android.hardware
package, provides classes and interfaces to help you
perform a wide variety of sensor-related tasks.
With the Android sensor framework you can: