ch5 1
ch5 1
Intent
• Eg- an activity may need to launch an email client and sends an email using the android
device. The activity may send an ACTION_SEND along with appropriate chooser to the
android intent resolver. The chooser, gives proper interface for the user to pick how to send
the email
• Eg: An activity needs to open URL in a browser. The activity sends a ACTION_WEB_SEARCH
intent to the Android Intent Resolver to open given URL in the browser. The Intent Resolver
parses through a list of Activities and chooses the one that would best match the Intent, in
this case, the Web Browser Activity. . The Intent Resolver then passes your web page to the
web browser and starts the Web Browser Activity
• An Intent provides a facility for performing late runtime binding between the code in
different applications. Its most significant use is in the launching of activities, where it can be
thought of as the glue between activities. It is basically a passive data structure holding an
abstract description of an action to be performed.
• Intent Structure
• Data-The data to operate on, such as a record in the contacts database, expressed as a uri
• Actions
• ACTION_VIEW tel:123 – displays the phone dialer with the number filled in
• ACTION_DIAL tel:123 – display the phone dialer with the number dialed in
• In addition to the primary attribute, some secondary attributes are used with an intent
• Category:gives additional information about the action to execute. Eg –
CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application,
while CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions
the user can perform on a piece of data
• Type - Specifies an explicit type (a MIME type) of the intent data. Normally the type is
inferred from the data itself. By setting this attribute, you disable that evaluation and force
an explicit type
• Component - Specifies an explicit name of a component class to use for the intent. Normally
this is determined by looking at the other information in the intent (the action, data/type,
and categories) and matching that with a component that can handle it. If this attribute is
set then none of the evaluation is performed, and this component is used exactly as is. By
specifying this attribute, all of the other Intent attributes become optional
• Extras – this is a bundle of any additional information. This can be used to provide extended
information to the component. For example, if an action is to send an e-mail message, extra
pieces of information could be provided of data here to supply a subject, body, etc
• Eg:
Display all pickers for data that can be opened with ContentResolver.openInputStream() allowing the
user to pick one of them and then some data inside of it and returning the resulting URI to the caller.
This can be used, for example, in an e-mail application to allow the user to pick some data to include
as an attachment.
• There are a variety of standard Intent action and category constants defined in the Intent
class, but applications can also define their own
• Intent Resolution
• The intent resolution mechanism revolves around matching an Intent against all of the
<intent-filter> descriptions in the installed application packages
• There are three pieces of information in the Intent that are used for resolution: the action,
type, and category.
• The appropriate component is determined based on the intent information supplied in the
AndroidManifest.xml file as follows
• The type is retrieved from the Intent's data, if not already supplied in the Intent. Like the
action, if a type is included in the intent (either explicitly or implicitly in its data), then this
must be listed by the component as one it handles.
• Like the action the data, must be listed by the component as one it can handle.
• ACTION_MAIN
• ACTION_VIEW
• ACTION_ATTACH_DATA
• ACTION_EDIT
• ACTION_PICK
• ACTION_CHOOSER
• ACTION_GET_CONTENT
• ACTION_DIAL
• ACTION_CALL
• ACTION_SEND
• ACTION_SENDTO
• ACTION_ANSWER
• ACTION_INSERT
• ACTION_DELETE
• ACTION_RUN
• ACTION_SYNC
• ACTION_PICK_ACTIVITY
• ACTION_SEARCH
• ACTION_WEB_SEARCH
• ACTION_FACTORY_TEST
ACTION_TIME_TICK
ACTION_TIME_CHANGED
ACTION_TIMEZONE_CHANGED
ACTION_BOOT_COMPLETED
ACTION_PACKAGE_ADDED
ACTION_PACKAGE_CHANGED
ACTION_PACKAGE_REMOVED
ACTION_PACKAGE_RESTARTED
ACTION_PACKAGE_DATA_CLEARED
ACTION_PACKAGES_SUSPENDED
ACTION_PACKAGES_UNSUSPENDED
ACTION_UID_REMOVED
ACTION_BATTERY_CHANGED
ACTION_POWER_CONNECTED
ACTION_POWER_DISCONNECTED
ACTION_SHUTDOWN
• CATEGORY_DEFAULT
• CATEGORY_BROWSABLE
• CATEGORY_TAB
• CATEGORY_ALTERNATIVE
• CATEGORY_SELECTED_ALTERNATIVE
• CATEGORY_LAUNCHER
• CATEGORY_INFO
• CATEGORY_HOME
• CATEGORY_PREFERENCE
• CATEGORY_TEST
• CATEGORY_CAR_DOCK
• CATEGORY_DESK_DOCK
• CATEGORY_LE_DESK_DOCK
• CATEGORY_HE_DESK_DOCK
• CATEGORY_CAR_MODE
• CATEGORY_APP_MARKET
• CATEGORY_VR_HOME
• EXTRA_ALARM_COUNT
• EXTRA_BCC
• EXTRA_CC
• EXTRA_CHANGED_COMPONENT_NAME
• EXTRA_DATA_REMOVED
• EXTRA_DOCK_STATE
• EXTRA_DOCK_STATE_HE_DESK
• EXTRA_DOCK_STATE_LE_DESK
• EXTRA_DOCK_STATE_CAR
• EXTRA_DOCK_STATE_DESK
• EXTRA_DOCK_STATE_UNDOCKED
• EXTRA_DONT_KILL_APP
• EXTRA_EMAIL
• EXTRA_INITIAL_INTENTS
• EXTRA_INTENT
• EXTRA_KEY_EVENT
• EXTRA_ORIGINATING_URI
• EXTRA_PHONE_NUMBER
• EXTRA_REFERRER
• EXTRA_REMOTE_INTENT_TOKEN
• EXTRA_REPLACING
• EXTRA_SHORTCUT_ICON
• EXTRA_SHORTCUT_ICON_RESOURCE
• EXTRA_SHORTCUT_INTENT
• EXTRA_STREAM
• EXTRA_SHORTCUT_NAME
• EXTRA_SUBJECT
• EXTRA_TEMPLATE
• EXTRA_TEXT
• EXTRA_TITLE
• EXTRA_UID
• EXTRA_USER_INITIATED
Intent filter
• It also includes a "priority" value which is used to order multiple matching filters.
• IntentFilter objects are often created in XML as part of a package’s AndroidManifest.xml file,
using <intent-filter> tags
• There are three Intent characteristics to filter on: the action, data, and categories
• For each of these, multiple possible matching values can be provided using
addAction(String), addDataType(String), addCategory(String). For actions, if no data
characteristics are specified, then the filter will only match intents that contain no data
• The data characteristic is itself divided into three attributes: type, scheme, authority, and
path.
• Any that are specified must match the contents of the Intent. If programmer specifies a
scheme but no type, only Intent that does not have a type (such as mailto:) will match; a
content: URI will never match because they always have a MIME type that is supplied by
their content provider.
• Specifying a type with no scheme has somewhat special meaning: it will match either an
Intent with no URI field, or an Intent with a content: or file: URI.
• If neither is specified, then only an Intent with no data or type will match.
• To specify an authority, programmer must also specify one or more schemes that it is
associated with.
• To specify a path, programmer also must specify both one or more authorities and one or
more schemes it is associated with.
• Filter rules
• Data Type matches if any of the given values match the Intent type. The Intent type is
determined by calling Intent#resolverType. A wildcard can be used for the MIME sub-type,
in both the Intent and IntentFilter, so that the type "audio/*" will match "audio/mpeg",
"audio/aiff", "audio/*", etc. MIME type matching here is case sensitive. Always use lower
case letters for MIME types.
• Filter rules
• Data Scheme matches if any of the given values match the Intent data's scheme. The Intent
scheme is determined by calling Intent#getData and Uri.getScheme() on tht uri. Scheme
matching here is case sensitive. Always use lower case letters
• Data Scheme Specific Part matches if any of the given values match the Intent's data scheme
specific part and one of the data schemes in the filter has matched the Intent, or no scheme
specific parts were supplied in the filter. The Intent scheme specific part is determined by
calling Intent#getData and Uri.getSchemeSpecificPart() on that uri. Case sentisitive so use
lowercase.
• Filter rules
• Data Authority matches if any of the given values match the Intent's data authority and one
of the data schemes in the filter has matched the Intent, or no authorities were supplied in
the filter. The Intent authority is determined by calling Intent#getData and Uri.getAuthority()
on the uri.
• Data Path matches if any of the given values match the Intent's data path and both a scheme
and authority in the filter has matched against the Intent, or no paths were supplied in the
filter. The Intent authority is determined by calling Intent#getData and Uri.getPath() on the
uri
• Categories match if all of the categories in the Intent match categories given in the filter.
Extra categories in the filter that are not in the Intent will not cause the match to fail. An
IntentFilter with no categories will only match an Intent that does not have any categories
Activity
• An activity represents a single screen with a user interface just like window or frame of
Java.Android activity is the subclass of ContextThemeWrapper class
• Activity class is a crucial component of an Android app, and the way activities are launched
and put together is a fundamental part of the platform's application model
• Unlike programming languages in which apps are launched with a main() method, Android
system initiates code in an Activity instance by invoking specific callback methods that
corresponds to specific stages of its life cycle
• The mobile-app experience differs from its desktop counterpart in that a user's interaction
with the app doesn't always begin in the same place. Instead, the user journey often begins
non-deterministically.
• For instance, if you open an email app from your home screen, you might see a list of emails.
By contrast, if you are using a social media app that then launches your email app, you might
go directly to the email app's screen for composing an email.
• The Activity class is designed to facilitate this paradigm. When one app invokes another, the
calling app invokes an activity in the other app, rather than the app as an atomic whole. In
this way, the activity serves as the entry point for an app's interaction with the user
• An activity provides the window in which the app draws its UI. This window typically fills the
screen, but may be smaller than the screen and float on top of other windows.
• Most apps contain multiple screens, which means they comprise multiple activities.
• Typically, one activity in an app is specified as the main activity, which is the first screen to
appear when the user launches the app.
• Each activity can then start another activity in order to perform different actions.
• For example, the main activity in a simple e-mail app may provide the screen that shows an
e-mail inbox. From there, the main activity might launch other activities that provide screens
for tasks like writing e-mails and opening individual e-mails.
• Activity class takes care of creating a window in which UI can be placed with
setContentView()
• The two methods of Activity all subclasses of Activity may implement are
onCreate(Bundle) – is where the activity is initialized. Here a call to setContentView() is done with a
reference to the layout resource that defines the UI. findViewById() is used retrieve any widgets that
should be interacted with
onPause() - is where programmer deals with the user pausing active interaction with the activity.
Any changes made by the user should at this point be committed
• To use activities in your app, you must register information about them in the app’s
manifest, and you must manage activity lifecycles appropriately..
• If an activity is in the foreground of the screen (at the highest position of the topmost stack),
it is active or running. This is usually the activity that the user is currently interacting with
• If an activity has lost focus but is still presented to the user, it is visible. It is possible if a new
non-full-sized or transparent activity has focus on top of your activity, another activity has
higher position in multi-window mode, or the activity itself is not focusable in current
windowing mode. Such activity is completely alive (it maintains all state and member
information and remains attached to the window manager).
• This is the first callback and called when the activity is first created
onStart()
• This callback is called when the activity becomes visible to the user
onResume()
• This is called when the user starts interacting with the application.
onPause()
• The paused activity does not receive user input and cannot execute any code and called
when the current activity is being paused and the previous activity is being resumed.
onStop()
onDestroy()
onRestart()
• This callback is called when the activity restarts after stopping it.
• The entire lifetime of an activity happens between the first call to createBundle() through to
a single final call to onDestroy(). An activity will do all setup of global state in onCreate(),
and release all remaining resources in onDestroy(). For example, if it has a thread running in
the background to download data from the network, it may create that thread in onCreate()
and then stop the thread in onDestroy()
• The visible lifetime of an activity happens between a call to onStart() until a corresponding
call to onStop(). During this time the user can see the activity on-screen, though it may not
be in the foreground and interacting with the user. Between these two methods you can
maintain resources that are needed to show the activity to the user. For example,
programmer can register a BroadcastReceiver in onStart() to monitor for changes that
impact the UI, and unregister it in onStop() when the user no longer sees what is displayed.
The onStart() and onStop() methods can be called multiple times, as the activity becomes
visible and hidden to the user.
• Broadcast Receivers simply respond to broadcast messages from other applications or from
the system itself. These messages are sometime called events or intents. For example,
applications can also initiate broadcasts to let other applications know that some data has
been downloaded to the device and is available for them to use, so this is broadcast receiver
who will intercept this communication and will initiate appropriate action.
• When a broadcast message arrives for the receiver, Android calls its onReceive() method and
passes it the Intent object containing the message. The broadcast receiver is considered to
be active only while it is executing this method. When onReceive() returns, it is inactive.
• Create BroadcastReceiver
• Register it
Creating BroadcastReceiver
Registering it
Event constants
android.intent.action.BATTERY_CHANGED
• Sticky broadcast containing the charging state, level, and other information about the
battery.
android.intent.action.BATTERY_LOW
android.intent.action.BATTERY_OKAY
android.intent.action.BOOT_COMPLETED
Event constants
android.intent.action.BUG_REPORT
android.intent.action.CALL
android.intent.action.CALL_BUTTON
• The user pressed the "call" button to go to the dialer or other appropriate UI for placing a
call.
android.intent.action.DATE_CHANGED
• The date has changed.
android.intent.action.REBOOT
• A provider is part of an Android application, which often provides its own UI for working
with the data.
• However, content providers are primarily intended to be used by other applications, which
access the provider using a provider client object.
• Together, providers and provider clients offer a consistent, standard interface to data that
also handles inter-process communication and secure data access.
• Typically programmer works with content providers in one of two scenarios; programmer
may want to implement code to access an existing content provider in another application,
or may want to create a new content provider in the application to share data with other
applications.
• A content provider presents data to external applications as one or more tables that are
similar to the tables found in a relational database. A row represents an instance of some
type of data the provider collects, and each column in the row represents an individual piece
of data collected for an instance
• Content providers can help an application manage access to data stored by itself, stored by
other apps, and provide a way to share data with other apps.
• They encapsulate the data, and provide mechanisms for defining data security.
• Content providers are the standard interface that connects data in one process with code
running in another process.
• Implementing a content provider has many advantages. Most importantly programmer can
configure a content provider to allow other applications to securely access and modify the
app data
• Content providers can be used if the programmers plan to share data. If they don’t plan to
share data, programmer may still use them because they provide an abstraction
• This abstraction allows programmer to make modifications to the application data storage
implementation without affecting other existing applications that rely on access to the data.
• In this scenario only the content provider is affected and not the applications that access it.
• Content providers offer granular control over the permissions for accessing data.
• One can choose to restrict access to a content provider from solely within the application,
grant blanket permission to access data from other applications, or configure different
permissions for reading and writing data.
• Content provider can be used to abstract the details for accessing different data sources in
the application.
• For example, your application might store structured records in a SQLite database, as well as
video and audio files. You can use a content provider to access all of this data
• Accessing a provider
• When the programmer wants to access data in a content provider, the ConentResolver
object is used in the application’s Context to communicate with the provider as a client.
• The ContentResolver object communicates with the provider object, an instance of a class
that implements ContentProvider
• The provider object receives data requests from clients, performs the requested action, and
returns the results.
• This object has methods that call identically-named methods in the provider object, an
instance of one of the concrete subclasses of ContentProvider.
• The ContentResolver methods provide the basic create, retrieve, update, and delete
functions of persistent storage.
• A common pattern for accessing a ContentProvider from the UI uses a CursorLoader to run
queries in the background
• The activity or fragment in the UI calls a CursorLoader to the query which gets the
ContentProvider using ContentResolver
• This allows the UI to continue to be available to the user while the query is running. This
pattern involves the interaction of a number of different objects, as well as the underlying
storage mechanism,
• To query a content provider, the query string is specified using Content URI
SQLite
• SQLite is a opensource SQL database that stores data to a text file on a device. Android
comes in with built in SQLite database implementation.
• SQLite supports all the relational database features. In order to access this database, you
don't need to establish any kind of connections for it like JDBC,ODBC e.t.c
• Database – Creation
• In order to create a database call the method openOrCreateDatabase with database name
and mode as a parameter. It returns an instance of SQLite database which programmer has
to receive in an object.
This method only opens the existing database with the appropriate flag mode. The common flags
mode could be OPEN_READWRITE OPEN_READONLY
openDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags) -It is similar to the above
method as it also opens the existing database but it does not define any handler to handle the errors
of databases
openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory)-It not only opens but
create the database if it not exists. This method is equivalent to openDatabase method.
Fragment
• A Fragment is a piece of an activity which enable more modular activity design. It can be
considered as a kind of sub-activity
• A fragment has its own layout and its own behaviour with its own life cycle callbacks.
• Fragments can be created by extending Fragment class and a fragment can be inserted into
the activity layout by declaring the fragment in the activity's layout file, as
a <fragment> element..
• With the introduction of fragment more flexibility can be introduced and it also removed the
limitation of having a single activity on the screen at a time.
• Now a single activity can comprise of multiple fragments which will have their own layout,
events and complete life cycle.
• onAttach()The fragment instance is associated with an activity instance.The fragment and
the activity is not fully initialized. Typically you get in this method a reference to the activity
which uses the fragment for further initialization work.
• onCreate() The system calls this method when creating the fragment. You should initialize
essential components of the fragment that you want to retain when the fragment is paused
or stopped, then resumed.
• onCreateView() The system calls this callback when it's time for the fragment to draw its
user interface for the first time. To draw a UI for your fragment, you must return
a View component from this method that is the root of your fragment's layout. You can
return null if the fragment does not provide a UI.
• onPause() The system calls this method as the first indication that the user is leaving the
fragment. This is usually where you should commit any changes that should be persisted
beyond the current user session.
• First of all decide how many fragments is to be there in an activity. For example suppose two
fragments to handle landscape and portrait modes of the device.
• Next based on number of fragments, create classes which will extend the Fragment class.
The Fragment class has callback functions. Any of the functions can be overridden based on
the requirements.
• Corresponding to each fragment, a layout file should be created as XML file. These files will
have layout for the defined fragments.
• Finally modify activity file to define the actual logic of replacing fragments based on the
requirement.
• Types
• Single frame fragments - Single frame fragments are using for hand hold devices like
mobiles, here we can show only one fragment as a view
• List fragments - fragments having special list view is called as list fragment
• Fragments transaction - Using fragment transaction, one fragment can be moved to another
fragment.
Service
• The prime aim of a service is to ensure that the application remains active in the background
so that the user can operate multiple applications at the same time.
• A service can run continuously in the background even if the application is closed or the user
switches to another application
• Further, application components can bind itself to service to carry out inter-process
communication
• There is a major difference between android services and threads. Thread is a feature
provided by the Operating system to allow the user to perform operations in the
background. While service is an android component that performs a long-running operation
about which the user might not be aware of as it does not have UI.
• Types of service
Foreground service
• Foreground services continue running even when the user isn't interacting with the app.
• When the programmer uses a foreground service, a notification must be displayed so that
users are aware that the service is running. This notification cannot be dismissed unless the
service is either stopped or removed from the foreground.
• Types of service
Background service
A background service performs an operation that isn't directly noticed by the user. For example, if an
app used a service to compact its storage, that would usually be a background service.
Bound
A bound service offers a client-server interface that allows components to interact with the service,
send requests, receive results, and even do so across processes with interprocess communication
(IPC). A bound service runs only as long as another application component is bound to it. Multiple
components can bind to the service at once, but when all of them unbind, the service is destroyed.
onStartCommand()
• The system calls this method when another component, such as an activity, requests that
the service be started, by calling startService(). If this method is implemented, it is the
responsibility of the programmer to stop the service when its work is done, by
calling stopSelf() or stopService() methods.
onBind()
• The system calls this method when another component wants to bind with the service by
calling bindService(). If this method is implemented, the programmer must provide an
interface that clients use to communicate with the service, by returning an IBinder object.
This method must always be implemented, but binding is not to be allowed, then null should
be returned.
onUnbind()
• The system calls this method when all clients have disconnected from a particular interface
published by the service
onRebind()
• The system calls this method when new clients have connected to the service, after it had
previously been notified that all had disconnected in its onUnbind(Intent).
onCreate()
• The system calls this method when the service is first created
using onStartCommand() or onBind(). This call is required to perform one-time set-up.
onDestroy()
• The system calls this method when the service is no longer used and is being destroyed. Your
service should implement this to clean up any resources such as threads, registered
listeners, receivers, etc.
MultimediaFramework
• Android includes Stagefright, a media playback engine at the native level that has built-in
software-based codecs for popular media formats.
• Stagefright audio and video playback features include integration with OpenMAX codecs,
session management, time-synchronized rendering, transport control, and DRM.
• Stagefright also supports integration with custom hardware codecs provided by you. To set a
hardware path to encode and decode media, you must implement a hardware-based codec
as an OpenMax IL (Integration Layer) component.
• Application Framework - At the application framework level is application code that utilizes
android.media APIs to interact with the multimedia hardware.
• Binder IPC -The Binder IPC proxies facilitate communication over process boundaries. They
are located in the frameworks/av/media/libmedia directory
• Native multimedia framework-At the native level, Android provides a multimedia framework
that utilizes the Stagefright engine for audio and video recording and playback. Stagefright
comes with a default list of supported software codecs and programmers can implement
their own hardware codec by using the OpenMax integration layer standard.
• OpenMAX integration layer - The OpenMAX IL provides a standardized way for Stagefright to
recognize and use custom hardware-based multimedia codecs called components. The
programmer must provide an OpenMAX plugin in the form of a shared library named
libstagefrighthw.so. This plugin links Stagefright with your custom codec components, which
must be implemented according to the OpenMAX IL component standard.
MediaPlayer class
Android provides many ways to control playback of audio/video files and streams. One of this way is
through a class called MediaPlayer.
To access built-in mediaplayer services like playing audio,video e.t.c this class can be used
Users can play audio or video from media files stored in the application's resources (raw resources),
from standalone files in the filesystem, or from a data stream arriving over a network connection, all
using MediaPlayer API
Methods:
isPlaying()
• This method just returns true/false indicating the song is playing or not
seekTo(position)
• This method takes an integer, and move song to that particular position millisecond
getCurrentPosition()
getDuration()
reset()
release()
In order to use this class, instantiate an object of this class and also specify the initListener
In this listener, specify the properties for TextToSpeech object, such as its language, pitch etc.
Values for Locale are US, CANADA_FRENCH, GERMANY, ITALY, JAPAN, CHINA
Once the language is set, speak() ,method can be invoked to speak the text
• This method adds a mapping between a string of text and a sound file.
getLanguage()
isSpeaking()
• This method checks whether the TextToSpeech engine is busy speaking.
setPitch(float pitch)
• This method sets the speech pitch for the TextToSpeech engine.
setSpeechRate(float speechRate)
shutdown()
stop()
Most Android-powered devices have built-in sensors that measure motion, orientation, and various
environmental conditions.
These sensors are capable of providing raw data with high precision and accuracy, and are useful if
the programmer want to monitor three-dimensional device movement or positioning, or want to
monitor changes in the ambient environment near a device.
For example, a game might track readings from a device's gravity sensor to infer complex user
gestures and motions, such as tilt, shake, rotation, or swing.
Likewise, a weather application might use a device's temperature sensor and humidity sensor to
calculate and report the dewpoint, or a travel application might use the geomagnetic field sensor
and accelerometer to report a compass bearing.
Programmer can access sensors available on the device and acquire raw sensor data by using the
Android sensor framework. The sensor framework provides several classes and interfaces that helps
the programmer perform a wide variety of sensor-related tasks.
The Android sensor framework lets the programmer access many types of sensors.
Hardware-based sensors are physical components built into a handset or tablet device. They derive
their data by directly measuring specific environmental properties, such as acceleration,
geomagnetic field strength, or angular change
Software-based sensors are not physical devices, although they mimic hardware-based sensors.
Software-based sensors derive their data from one or more of the hardware-based sensors and are
sometimes called virtual sensors or synthetic sensors. The linear acceleration sensor and the gravity
sensor are examples of software-based sensors..
The Sensors and data about the sensors can be obtained using Android sensor framework. It is a part
of the android.hardware package
SensorManager-This class can be used to create an instance of the sensor service. This class provides
various methods for accessing and listing sensors, registering and unregistering sensor event
listeners, and acquiring orientation information. This class also provides several sensor constants
that are used to report sensor accuracy, set data acquisition rates, and calibrate sensors.
Sensor-this class can be used to create an instance of a specific sensor. This class provides various
methods that lets the programmer determine a sensor's capabilities.
AsyncTasks
AsyncTask allows the progrmmer to run the instruction in the background and then synchronize
again with the main thread.
This class is used to do background operations that will update the UI(user interface). Mainly it is
used for short operations that will not effect on our main thread.
By default, the application code runs in the main thread and every statement therefore execute in a
sequence. If the programmer need to perform long tasks/operations then the main thread is blocked
until the corresponding operation has finished.
For providing a good user experience in the application AsyncTasks class that runs in a separate
thread is used. This class will execute everything in doInBackground() method inside of other thread
which doesn’t have access to the GUI where all the views are present. The onPostExecute() method
of this class synchronizes itself again with the main UI thread and allows it to make some updating.
This method is called automatically after the doInBackground method finished its work.
Methods of AsyncTask
onPreExecute() – It invoked on the main UI thread before the task is executed. This method is
mainly used to setup the task for instance by showing a progressbar in the UI
Methods of AsyncTask
ACTION_IMAGE_CAPTURE_SECURE
• It returns the image captured from the camera , when the device is secured
ACTION_VIDEO_CAPTURE
EXTRA_SCREEN_ORIENTATION
• EXTRA_FULL_SCREEN
• It is used to control the user interface of the ViewImage
• INTENT_ACTION_VIDEO_CAMERA
• EXTRA_SIZE_LIMIT
Android platform includes support for the Bluetooth framework that allows a device to wirelessly
exchange data with other Bluetooth devices.
Android provides BluetoothAdapter class to communicate with Bluetooth. An object of this can be
created by calling the static method getDefaultAdapter()
In order to enable the Bluetooth of the device, call the intent with the following Bluetooth constant
ACTION_REQUEST_ENABLE
ACTION_REQUEST_DISCOVERABLE
ACTION_STATE_CHANGED
• This constant will notify that Bluetooth state has been changed
ACTION_FOUND
• This constant is used for receiving information about each device that is discovered
Methods
enable()
isEnabled()
The methods
disable()
getName()
getState()
startDiscovery()
• This method starts the discovery process of the Bluetooth for 120 seconds.
Animation
The Animations Framework allows to create visually attractive animations and transitions in the
apps.
Animation is the process of creating motion and shape change. To use Animations in Android ,
Android has provided a class called Animation.
• View Animation:This is the simplest animation used in Android. It define the properties of
our Views that should be animated using a technique called Tween Animation. It take the
following parameters i.e. size, time duration , rotation angle, start value , end value, and
perform the required animation on that object. Programmer can execute the animation by
specifying transformations on the View. This can be done in XML resource files or
programmatically.
• Android View animation can make animation on any View objects, such as ImageView,
TextView or Button objects. View animation can only animate simple properties like
position, size, rotation, and the alpha property that allows you animate the transparency of
a View. The drawback of this mechanism is that it can only be applied to Views
Property Animation
• Property animations are highly customizable, programmer can specify the duration, the
number of repeats, and the frame rate of the animation. The Property Animation system is
always preferred for more complex animations.
• Property animations allow to animate any property of any object from one value to another
over a specified duration.
Drawable Animation:
• This animation allows the user to load drawable resources and display them one frame after
another. This method of animation is useful when user wants to animate things that are
easier to represent with Drawable resources.