You are on page 1of 43

Android: Android is an open-source software stack that includes the operating system,

middleware, and key mobile applications, along with a set of API libraries for writing
applications that can shape the look, feel and functions of the devices which they run.
Android is an ecosystem made up of a combination of three components:

A free, open-source operating system for embedded devices

An open-source development platform for creating applications

Devices, particularly mobile phones, that run the Android operating system and
the applications created for it

Some Mobile Platforms

Android developed by Google.

iOS developed by Apple .

Symbian developed by Nokia 2008

Windows Phone 7 developed by Microsoft

Blackberry OS developed by RIM (Research in Motion)

Q. What are important features of android?


Android is made up of several necessary and dependent parts, including the following:

A Compatibility Definition Document (CDD) and Compatibility Test Suite (CTS)


that describe the capabilities required for a device to support the software stack.

A Linux operating system kernel that provides a low-level interface with the
hardware, memory management, and process control, all optimized for mobile
and embedded devices.

Open-source libraries for application development, including SQLite, WebKit,


OpenGL, and a media manager.

A run time used to execute and host Android applications, including the Dalvik
Virtual Machine (VM) and the core libraries that provide Android-specific
functionality. The run time is designed to be small and efficient for use on mobile
devices.

An application framework that agnostically exposes system services to the


application layer, including the window manager and location manager,
databases, telephony, and sensors.

A user interface framework used to host and launch applications.

A set of core pre-installed applications.

A software development kit (SDK) used to create applications, including the


related tools, plug-ins, and documentation.

1|Page

Q. Why android is so popular?


Global partnerships and large installed base: Building on the contributions of
the open-source Linux community and more than 300 hardware, software, and carrier
partners, Android has rapidly become the fastest-growing mobile OS.
Powerful development framework: Easily optimize a single binary for phones,
tablets, and other devices.
Open marketplace for distributing apps: Google Play is the premier marketplace
for selling and distributing Android apps. When you publish an app on Google Play, you
reach the huge installed base of Android.
Q. Write name of some native android application
Native Android Applications: Android devices typically come with a suite of
preinstalled applications that form part of the Android Open Source Project (AOSP),
including, but not necessarily limited to, the following:

An e-mail client

An SMS management application

A full PIM (personal information management) suite, including a calendar and


contacts list

A WebKit-based web browser

A music player and picture gallery

A camera and video recording application

A calculator

A home screen

An alarm clock
In many cases Android devices also ship with the following proprietary Google
mobile applications:

The Google Play Store for downloading third-party Android applications

A fully featured mobile Google Maps application, including StreetView, driving


directions, and turn-byturn navigation, satellite views, and traffic conditions

The Gmail email client

The Google Talk instant-messaging client

The YouTube video player

2|Page

Q. What Android has that other platforms don't have?


The following non comprehensive list details some of the features available on Android
that may not be available on all modern mobile development platforms:
Google Maps applicationsGoogle Maps for Mobile has been hugely popular, and
Android offers a Google Map as an atomic, reusable control for use in your applications.
Background services and applicationsFull support for background applications
and services lets you create applications based on an event-driven model, working
silently while other applications are being used or while your mobile sits ignored until it
rings, flashes, or vibrates to get your attention.
Shared data and inter-process communication
Using Intents and Content Providers, Android lets your applications exchange messages,
perform processing, and share data.
All applications are created equalAndroid doesn't differentiate between native
applications and those developed by third parties.
Wi-Fi Direct and Android BeamUsing these innovative new inter-device
communication APIs, you can include features such as instant media sharing and
streaming.
Home-screen Widgets, Live Wallpaper, and the quick search boxUsing
Widgets and Live Wallpaper, you can create windows into your application from the
phone's home screen. The quick search box lets you integrate search results from your
application directly into the phone's search functionality.
Android Application Architecture
Android's architecture encourages component reuse, enabling you to publish and share
Activities, Services, and data with other applications, with access managed by the
security restrictions you define. The same mechanism that enables you to produce a
replacement contact manager or phone dialler can let you expose your application's
components in order to let other developers build on them by creating new UI front
ends or functionality extensions.
The following application services are the architectural cornerstones of all Android
applications, providing the framework you'll be using for your own software:
Activity Manager and Fragment Manager
Control the lifecycle of your Activities and Fragments, respectively, including
management of the Activity stack (described in Chapters 3 and 4).
ViewsUsed to construct the user interfaces for your Activities and Fragments, as
described in Chapter 4.
3|Page

Notification ManagerProvides a consistent and nonintrusive mechanism for


signalling your users, as described in Chapter 10.
Content ProvidersLets your applications share data, as described in Chapter 8.
Resource ManagerEnables non-code resources, such as strings and graphics, to be
externalized, as shown in Chapter 3.
IntentsProvides a mechanism for transferring data between applications and their
components, as described in Chapter 5.
Types of Android Applications
Most of the applications you create in Android will fall into one of the following
categories:
ForegroundAn application that's useful only when it's in the foreground and is
effectively suspended when it's not visible. Games are the most common examples.
BackgroundAn application with limited interaction that, apart from when being
configured, spends most of its lifetime hidden. These applications are less common, but
good examples include call screening applications, SMS auto-responders, and alarm
clocks.
IntermittentMost well-designed applications fall into this category. At one extreme
are applications that expect limited interactivity but do most of their work in the
background. A common example would be a media player. At the other extreme are
applications that are typically used as foreground applications but that do important
work in the background. Email and news applications are great examples.
Widgets and Live WallpapersSome applications are represented only as a homescreen Widget or as a Live Wallpaper. Complex applications are often difficult to
pigeonhole into a single category and usually include elements of each of these types.
When creating your application, you need to consider how it's likely to be used and then
design it accordingly. The following sections look more closely at some of the design
considerations for each application type.
Android Emulator: The emulator is a tool for testing and debugging
applications, particularly when we dont have a real device for experimentation.
Android applications consist of loosely coupled components, bound by the
application manifest that describes each component and how they interact. The
manifest is also used to specify the application's metadata, its hardware and platform
requirements, external libraries, and required permissions. The following components
comprise the building blocks for all your Android applications:
ActivitiesYour application's presentation layer. The UI of your application is built
around one or more extensions of the Activity class. Activities use Fragments and Views
4|Page

to layout and display information, and to respond to user actions. Compared to desktop
development, Activities are equivalent to Forms. You'll learn more about Activities later
in this chapter.
ServicesThe invisible workers of your application. Service components run without a
UI, updating your data sources and Activities, triggering Notifications, and
broadcasting Intents. They're used to perform long running tasks, or those that require
no user interaction (such as network lookups or tasks that need to continue even when
your application's Activities aren't active or visible.) You'll learn more about how to
create and use services in Chapter 9, Working in the Background.
Content ProvidersShareable persistent data storage. Content Providers manage
and persist application data and typically interact with SQL databases. They're also the
preferred means to share data across application boundaries. You can configure your
application's Content Providers to allow access from other applications, and you can
access the Content Providers exposed by others. Android devices include several native
Content Providers that expose useful databases such as the media store and contacts.
You'll learn how to create and use Content Providers in Chapter 8, Databases and
Content Providers.
IntentsA powerful inter application message passing framework. Intents are used
extensively throughout Android. You can use Intents to start and stop Activities and
Services, to broadcast messages system-wide or to an explicit Activity, Service, or
Broadcast Receiver, or to request an action be performed on a particular piece of data.
Explicit,
implicit,
and
broadcast
Intents
are
explored
in
more
detail in Chapter 5, Intents and Broadcast Receivers.
Broadcast ReceiversIntent listeners. Broadcast Receivers enable your application
to listen for Intents that match the criteria you specify. Broadcast Receivers start your
application to react to any received Intent, making them perfect for creating event
driven applications. Broadcast Receivers are covered with Intents in Chapter 5.
WidgetsVisual application components that are typically added to the device home
screen. A special variation of a Broadcast Receiver, widgets enable you to create
dynamic, interactive application components for users to embed on their home screens.
You'll learn how to create your own widgets in Chapter 1 4, Invading the Home
Screen.
NotificationsNotifications enable you to alert users to application events without
stealing focus or interrupting their current Activity. They're the preferred technique for
getting a user's attention when your application is not visible or active, particularly from
within a Service or Broadcast Receiver. For example, when a device receives a text
message or an email, the messaging and Gmail applications use Notifications to alert
5|Page

you by flashing lights, playing sounds, displaying icons, and scrolling a text summary.
You can trigger these notifications from your applications, as discussed in Chapter 1 0,
Expanding the User Experience. By decoupling the dependencies between application
components, you can share and use individual Content Providers, Services, and even
Activities with other applicationsboth your own and those of third parties.

Android questions and Answers

1.
bmgr
a)take
backup
b)to
c)wipe
archived
d)all of the above

ans:

tool

data

of
restore
for

is

used
the

specific

to
applications
operations
application

2.
foreground
service
a)starts
when
you
call
start
foreground()
b)may
or
may
not
provide
a
notification
for
the
status
bar
c)notification can't be dismissed unless the service is either stopped or removed from
the
6|Page

foreground
d)both

&

ans:d
3. A1,A2,A3 and A4 are activities called using intents.Then A1-A4-A2--A3.A4 calls A2
with
intent flag FLAG_ACTIVITY_NO_HISTORY.When finish method is called on A3, What
will
be
the
currtent
a)A1
b)A4
c)A3
d)A2

running

ans:

activity?

4. A1,A2,A3 and A4 are activities called using intents.Then A1-A2-A4--A3.A2 calls A4


with
intent flag FLAG_ACTIVITY_CLEAR_TOP.When finish() method is called on A3, what
will
be
the
current
a)A4
b)A3
c)A2
d)A1
Ans:

running

activity?

5. A1,A2,A3 and A4 are activities called using intents.Then A1-A2-A3-A4. A3 calls A4


with
no
intent flag, when finish() method called on A4. What will be the current running
activity?
a)A2
7|Page

b)A3
c)A4
d)A1
Ans:
6.
a)
b)
c)
d)

b
The

plus(+)

means

in

Identify
it
Create
new
id
XML
parser
should
Both

statement
as

android:id="@+id/my_id"?

an

id
add
to
and
exapnd
&

and
parse
a

Ans:

resource
resources
id
string
b.
b

7. When you want system to run the service indefinitely, by restarting it when get killed,
use
a)
START_NOT_STICKY
b)
START_REDELIVER_INTENT
c)
START_STICKY
d)
START_SERVICE_INDEFINITELY
Ans:

8)
a)
b)
c)
d)

Android

To

system

broadcast
broadcast
invoke
other
All

uses

applications
of

intents

system
custom
from
the

your

Ans:
9)
a)
b)
c)
d)
8|Page

to
intents
intents
application.
above.
d

'Screen

has

turned
Normal
Ordered
background

off'

is

an

example
broadcast
broadcast
operation
None

Ans:

10) If you try to acces the column which does not exit, system throws
a)
NullPointerException
b)
illegalArgumentException
c)
ArrayIndexOutOfBoundsException
d)
SQLException
Ans:
11)

b
Maximum

results

returned

by

getFromLocationName()

method

can

be

a)
b)
c)
d)

2
3
4
5

Ans:

12. The methods startForeground() and stopForeground() were introduced in which


API
level.
a)
b)
C)
d)

2.0
3.0
1.5
2.2

Ans:

13. Should always first check availability of audio effects by calling the following method
on
the
a)
b)
c)
9|Page

corresponding

audio

isvaluable

effect

class.
ischeckable()
isavailable()
()

d)

iscaview()

Ans:

14. Applications that require filtering based on screen size can use the attributes.
a)
b)
c)
d)

<supportmultiple-screens>
<supports-screens>
<supportall-screens
supportevery-screen

Ans:

15.
a)
b)
c)
d)

what

is

false

with

respect

to

onBind()

is

called when another component wants to bind with a service


calling
startService()
results
in
a
call
to
onBind()
if
you
don't
want
to
allow
binding
then
return
null
if
you
want
to
allow
binding
then
return
Ibinder
object

Ans: b

Android Objective type Question and Answers


Android

Objective

type

Question

and

Answers

1) Once installed on a device, each Android application lives in_______?


a)device
memory
b)external
memory
c)
security
sandbox
d)None
of
the
above
Ans)
c
2)Parent
a)Object
b)Context
c)ActivityGroup
d)ContextThemeWrapper
10 | P a g e

class

of

Activity?

Ans)

3)What
are
the
a)AccountAuthenticatorActivity
b)
c)
d)
e)
f)
all
Ans)
4)What
are
the
a)LauncherActivity
b)PreferenceActivity
c)
d)All
Ans)
5)Parent
a)Object
b)Context
c)
d)ContextThemeWrapper
Ans)

Direct

indirect

subclasses

the

Direct

of

Activity?

ActivityGroup
ExpandableListActivity
FragmentActivity
ListActivity
aove
f

subclasses

the
class

of

of

Activity?

TabActivity
above
d
Service?

ContextWrapper
c

6)What
are
the
indirect
Direct
subclasses
of
Services?
a)
RecognitionService
b)
RemoteViewsService
c)SpellCheckerService
d)InputMethodService
Ans)
d
7)Which
component
is
not
activated
by
an
Intent?
a)Activity
b)Services
c)ContentProvider
d)BroadcastReceiver
Ans)
c
8)When
contentProvider
would
be
activated?
a)Using
Intent
b)Using
SQLite
c)Using
ContentResolver
11 | P a g e

d)None
of
the
above
Ans)
c
9)Which of the important device characteristics that you should consider as you design
and
develop
your
application?
a)Screen
size
and
density
b)Input
configurations
c)Device
features
d)Platform
Version
e)All
of
the
above
Ans)
e
10)Which
are
the
screen
sizes
in
Android?
a)small
b)normal
c)large
d)extra
large
e)All
of
the
above
Ans)
e
11)Which
are
the
screen
densities
in
Android?
a)low
density
b)medium
density
c)high
density
d)extra
high
density
e)All
of
the
above
Ans)
e
12)You can shut down an activity by calling its _______ method
a)onDestory()
b)finishActivity()
c)finish()
d)None
of
the
above
Ans)
c
13)What is the difference between Activity context and Application Context?
a) The Activity instance is tied to the lifecycle of an Activity.
while the application instance is tied to the lifecycle of the application,
b) The Activity instance is tied to the lifecycle of the application,
while the application instance is tied to the lifecycle of an Activity.
c) The Activity instance is tied to the lifecycle of the Activity,
while the application instance is tied to the lifecycle of an application.
d)
None
of
the
above
Ans)
a
14)Which
one
is
NOT
related
to
fragment
class?
12 | P a g e

a)DialogFragment
b)ListFragment
c)PreferenceFragment
d)CursorFragment
Ansa)d
15)Definition
of
Loader?
a) loaders make it easy to asynchronously load data in an activity or fragment.
b) loaders make it easy to synchronously load data in an activity or fragment.
c) loaders does not make it easy to asynchronously load data in an activity or fragment.
d)
None
of
the
above.
Ans)
a
16)Characteristics
of
the
Loaders?
a)They
are
available
to
every
Activity
and
Fragment.
b)They
provide
asynchronous
loading
of
data.
c)They monitor the source of their data and deliver new results when the content
changes.
d)They automatically reconnect to the last loader's cursor when being recreated after a
configuration change. Thus, they don't need to re-query their data.
e)All
of
the
above.
Ans)
e
17)How
many
ways
to
start
services?
a)Started
b)Bound
c)a
&
b
d)None
of
the
above.
Ans)
c
18)If your service is private to your own application and runs in the same process as the
client (which is common), you should create your interface by extending the
________class?
a)
Messenger
b)
Binder
c)
AIDL
d)None
of
the
above
Ans)
b
19)If you need your interface to work across different processes, you can create an
interface
for
the
service
with
a
________?
a)Binder
b)Messenger
c)AIDL
13 | P a g e

d)

or

c
Ans)
d
20)AsyncTask allows you to perform asynchronous work on your user interface. It
performs the blocking operations in a worker thread and then publishes the results on
the
UI
thread.
a)true
b)false
Ans)
a
21)Layouts
in
android?
a)Frame
Layout
b)Linear
Layout
c)Relative
Layout
d)Table
Layout
e)All
of
the
above
Ans)
e
22)
Dialog
classes
in
android?
a)AlertDialog
b)ProgressDialog
c)DatePickerDialog
d)TimePickerDialog
e)All
of
the
above
Ans)
e
23)If you want share the data accross the all applications ,you should go for?
a)Shared
Preferences
b)Internal
Storage
c)SQLite
Databases
d)content
provider
Ans)
d
24)Difference
between
android
api
and
google
api?
a)The google API includes Google Maps and other Google-specific libraries. The
Android
one
only
includes
core
android
libraries.
b)The google API one only includes core android libraries. The Android includes
Google
Maps
and
other
Google-specific
libraries.
c)None
of
the
above.
Ans) a
Android: Menus and Dialogs

Table
1. Menus
14 | P a g e

of

contents:

Options menu
Context menu
Sub menu
Creating different Menus
2. Dialogs
Alert Dialog
Progressbar dialog
DatePicker dialog
TimePicker Dialog
Toast
Creating different dialogs
Menus
Menus provide familiar interfaces to expose application functions without sacrificing
screen space.
Android offers an easy programming interface to provide standardized application
menus.
Android offers three fundamental types of application menus:
Options Menu
Context Menu
Sub-menu

Options

Menu:

By default, every Activity supports an Options menu of actions or options. It is revealed


by pressing the device MENU key.
Options Menu has two groups of menu items:
Icon Menu
15 | P a g e

Collection of maximum of six menu items


Supports Icons and short-cuts
Expanded Menu
Exposed by the 'More' menu item
Displayed when the icon menu becomes over-loaded
Comprised of sixth options menu item and the rest.

16 | P a g e

Create Options Menu:


Following methods are provided by Activity class to create an Options menu :
1 public boolean onCreateOptionsMenu(Menu menu)
2 public boolean onPrepareOptionsMenu(Menu menu)
3 public boolean onOptionsItemSelected(MenuItem item)
4 Override onCreateOptionsMenu() callback method, to add items to Options
menu using menu.add() method.

17 | P a g e

menu.add() adds a MenuItem and returns the newly created object to set additional
properties like icon, shortcut, ...etc.
public abstract MenuItem add(groupId, itemId, order, CharSequence)
Override onOptionsItemSelected() callback method to perform any action for a selected
Options menu item by identifying its id using item.getItemId().
public abstract int getItemId()
Override onPrepareOptionsMenu() callback method to update the menu dynamically
each time it gets displayed.

Options Menu Life Cycle:

Options
/*
Creates
public
boolean
menu.add(0,
menu.add(0,
return
}
/*
Handles
18 | P a g e

Menu

Example:

the
menu
items
onCreateOptionsMenu(Menu
menu)
1,
0,
"Menu
2,
0,
"Menu

item

selections

*/
{
1");
2");
true;
*/

public
switch
case
return
case
return
}
return
}

boolean
1:
2:

onOptionsItemSelected(MenuItem
(item.getItemId())
//Action
for
//Action

for

item)
Menu
Menu

{
{
1
true;
2
true;
false;

/*
Re-write
the
Options
Menu
as
it
is
opened
*/
public
boolean
onPrepareOptionsMenu(Menu
menu)
{
//Action
to
modify
Menu
each
time
it
is
opened.
SubMenu
sm1
=
(SubMenu)menu.getItem(0);
sm1.setIcon(R.drawable.icon);
sm1.add("NM
X");
menu.getItem(4).setIcon(R.drawable.icon);
return
super.onPrepareOptionsMenu(menu);
}

Sub

Menu:

Sub menu is a floating menu, it can be a child menu of options menu or context
menu.
It

supports

checkboxes,

radio

buttons

It does not support item icons, or nested sub menus.

19 | P a g e

and

shortcut

keys.

Context Menu
Context menu is a floating menu that is associated with a control.
Context menu is launched when the control has the focus and the D pad is pressed.
Context menus can be assigned to any View within an Activity.
It provides functions relating to the view, to which it is registered.
It supports submenus, checkboxes, radio buttons.
It does not support shortcuts and icons.

20 | P a g e

Create

Context

Menu:

Methods provided by Activity class to create and register an Context menu are :
public void onCreateContextMenu(ContextMenu, View, ContextMenuInfo)
public boolean onContextItemSelected(MenuItem item)
public void registerForContextMenu(view)
Override onCreateContextMenu() callback method, to add items to Context menu using
menu.add() method.
menu.add() adds a MenuItem and returns the newly created object to set properties
like checkboxes, radio buttons ...etc.
Override onContextItemSelected() callback method to perform any action for a selected
item by its id using item.getItemId().
Call registerForContextMenu(view) method inside onCreate() method to register the
context menu for a view.

Context Menu Life Cycle:

21 | P a g e

Context

Menu

Example:

/*
Register
a
view
to
*/
public
void
onCreate(Bundle
savedInstanceState){
super.onCreate(savedInstanceState);
Button
update
=
new
Button(this);
update.setText(UPDATE);
setContentView(update);
registerForContextMenu(update);
}
/*
Create
a
Context
Menu
*/
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo
menuInfo)
{
super.onCreateContextMenu(menu,
v,
menuInfo);
menu.add(0,
1,
0,
"Edit");
menu.add(0,
2,
0,
"Delete");
}
/*
public
switch
case
return
case
return
default:
}
}

22 | P a g e

Action
boolean
1:

on
item
selection
onContextItemSelected(MenuItem
item)
(item.getItemId())
//Action
for
menu
item

2:

//Action
return

for

*/
{
{
Edit
true;
Menu
item
Delete
true;
super.onContextItemSelected(item);

Context

sub

Menu:

Menu class provides a method named addSubMenu() to add sub menus under an
Options menu or a Context menu.
public abstract SubMenu addSubMenu(group, item, order, String)
Submenu.add() method is used to add sub-menu items.
onOptionsItemSelected() callback method for a SubMenu item refers to it's parent's
callback method.
Inside onOptionsItemSelected() callback the state of the radio button/ checkbox must
be set, if the submenu item is a radio button or checkbox.

Dialog:

A dialog is a small window that appears in front of an Activity.


The underlying Activity loses focus and the dialog accepts all user interaction.
Normally used for notifications and short activities that directly relate to the application
in progress.
Android supports following types of dialogs.
1
2
3
4

Date
Time
5

Alert
Progress
Picker
Picker

Dialog
Dialog
Dialog
Dialog
Toast

Alert Dialog:
A dialog that can manage zero, one, two or three buttons.
It can also manage a list of selectable items that can include checkboxes or radio
buttons.
The AlertDialog is capable of constructing most dialog user interfaces and is the
suggested dialog type.
AlertDialog class is a subclass of Dialog class and has a nested subclass
23 | P a g e

AlertDialog.Builder to construct a dialog.

Other Dialogs:
Progress Dialog
A dialog that displays a progress wheel or progress bar.
It supports buttons like in AlertDialog.
DatePicker Dialog
A dialog that allows the user to select a date.
TimePicker Dialog
A dialog that allows the user to select a time.

Toast:

A toast is a transient Dialog box containing a quick little message for the user.
Toasts never receive focus and they dont interrupt the active application.
They provide an ideal mechanism for alerting users to events occurring in background
Services without interrupting foreground applications.
Toast class provides a static method to create a standard toast display window.
static Toast makeText(context, text, duration)
Examples : Volume control, message for change settings.

Create

A dialog is always created and displayed as a part of an Activity.


Activity provides following methods to create and display dialogs,
onCreateDialog(int id)
onPrepareDialog(int id, Dialog dialog)
showDialog(int id)
24 | P a g e

Dialog:

Override the onCreateDialog(int id) callback method to create a dialog.


Override the onPrepareDialog(id, dialog) callback method to populate the dialog over
the screen each time it gets displayed.
Call the showDialog(int id) method to display a dialog.

Dialog Life Cycle:

Create

Dialog:

Override
onCreateDialog(id)
to
create
a
dialog
protected
Dialog
onCreateDialog(int
id)
{
switch(id){
case
DIALOG_ALERT_ID:
//Create
required
dialog
and
return
object
case
DIALOG_DISP:
//Create
required
dialog
and
return
object
case
DIALOG_PROGRESS:
//Create
required
dialog
and
return
object
default:
return
super.onCreateDialog(id);
}
Call
showDialog(id)
to
display
the
corresponding
dialog
showDialog(DIALOG_PROGRESS);
Override
onPrepareDialog()
to
protected
void
onPrepareDialog(int
super.onPrepareDialog(id,
25 | P a g e

modify
id,
Dialog

dialog
dialog)
{
dialog);

switch(id)
case
//Modify
case
//Modify
case
//Modify
default
break;
}
}
Create

in

dialog

in

dialog

in

dialog

Alert

{
DIALOG_ALERT_ID:
and
break;
DIALOG_DISP:
and
break;
DIALOG_PROGRESS:
and
break;
:

Dialog:

Create a dialog builder using AlertDialog.Builder by passing context.


AlertDialog.Builder
builder
=
new
AlertDialog.Builder(this);
Set
all
required
properties
for
the
created
builder.
builder.setMessage(message
to
display)
.setTitle(title
to
display)
.setCancelable(false);
//Can
set
different
buttons
here
setPositiveButton("Yes",
new
DialogInterface.OnClickListener()
{
//override
onClick()
and
perform
required
operation
like
finish()
}
setNegativeButton("No",
new
DialogInterface.OnClickListener()
{
//override
onClick()
and
perform
required
operation
like
cancel()
})
Retrieve
the
Alert
dialog
object
with
builder.create().
AlertDialog
alertObj
=
builder.create();
Create

Progress

Dialog:

Create
a
progress
dialog
object
ProgressDialog
progress
=
new
ProgressDialog(mContext);
Set
all
the
required
properties
and
return
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setTitle("Loading...");
progress.setMessage("Loading.
Please
wait...");
26 | P a g e

progress.setCancelable(false);
Create
the
object
by
its
ProgressDialog
dialog
=
"Loading.
Please
//Can
set
other
dialog.setCancelable(true);
dialog.setIcon(R.drawable.icon);
Create

Time

show()
method,
as
shown
below.
ProgressDialog.show(this,
"Loading...",
wait...",
true);
properties
here
also

Picker

Dialog:

Create a TimePickerDialog object by passing context and other parameters, as


shown
below.
//Get
the
current
Time
final
Calendar
c
=
Calendar.getInstance();
mHour
=
c.get(Calendar.HOUR_OF_DAY);
mMinute
=
c.get(Calendar.MINUTE);
//Create
and
return
the
TimePickerDialog
object
return
new
TimePickerDialog(this,
new
OnTimeSetListener()
{
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
//Perform
operation
on
time
set
}},
mHour,
mMinute,
true);
Create

Date

picker

dialog:

Create a DatePickerDialog object by passing context and other parameters, as shown


below.
//Get
the
current
Date
final
Calendar
c
=
Calendar.getInstance();
mYear
=
c.get(Calendar.YEAR);
mMonth
=
c.get(Calendar.MONTH);
mDay
=
c.get(Calendar.DAY_OF_MONTH);
//Create
and
return
the
DatePickerDialog
object
return new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public
void
onDateSet(DatePicker
view,
int
year,
int
monthOfYear,
int
dayOfMonth)
{
//Perform
operation
on
date
set
}
},
mYear,
mMonth,
mDay);
27 | P a g e

Create

Toast:

Create
a
Toast
object
with
application
context.
Toast
t
=
new
Toast(getApplicationContext());
Set
properties
like
text,
duration
and
position.
t.setDuration(Toast.LENGTH_LONG);
t.setText("Dialog
Displayed
from
Toast");
t.setGravity(Gravity.LEFT,
10,
100);
//Position,
xOffset
and
yOffset
Display
a
Toast
using
its
show()
method.
t.show();
Create
directly
using
its
static
method
makeText()
as
below.
Toast
t
=
Toast.makeText(getApplicationContext(),
"Dialog
Displayed",
Toast.LENGTH_SHOT);

Android Questions and Answers for written exams

1.
a)take
b)to
c)wipe
d)all

bmgr
backup
archived

tool

data
of

of
restore
for

is

used
the

specific
the

ans:

to
applications
operations
application
above
d

2.
foreground
service
a)starts
when
you
call
start
foreground()
b)may
or
may
not
provide
a
notification
for
the
status
bar
c)notification can't be dismissed unless the service is either stopped or removed from
the
foreground
d)both

&

ans:d
3. A1,A2,A3 and A4 are activities called using intents.Then A1-A4-A2--A3.A4 calls A2
28 | P a g e

with
intent flag FLAG_ACTIVITY_NO_HISTORY.When finish method is called on A3, What
will
be
the
currtent
a)A1
b)A4
c)A3
d)A2

running

ans:

activity?

4. A1,A2,A3 and A4 are activities called using intents.Then A1-A2-A4--A3.A2 calls A4


with
intent flag FLAG_ACTIVITY_CLEAR_TOP.When finish() method is called on A3, what
will
be
the
current
a)A4
b)A3
c)A2
d)A1

running

Ans:

activity?

5. A1,A2,A3 and A4 are activities called using intents.Then A1-A2-A3-A4. A3 calls A4


with
no
intent flag, when finish() method called on A4. What will be the current running
activity?
a)A2
b)A3
c)A4
d)A1
Ans:
6.

b
The

29 | P a g e

plus(+)

means

in

statement

android:id="@+id/my_id"?

a)
b)
c)
d)

Identify
it
Create
new
id
XML
parser
should
Both

as

an

id
add
to
and
exapnd
&

and
parse
a

Ans:

resource
resources
id
string
b.
b

7. When you want system to run the service indefinitely, by restarting it when get killed,
use
a)
START_NOT_STICKY
b)
START_REDELIVER_INTENT
c)
START_STICKY
d)
START_SERVICE_INDEFINITELY
Ans:

8)
a)
b)
c)
d)

Android

To

system

broadcast
broadcast
invoke
other
All

uses

applications
of

intents

system
custom
from
the

your

Ans:
9)

to
intents
intents
application.
above.
d

'Screen

a)
b)
c)
d)
Ans:

has

turned
Normal
Ordered
background

off'

is

an

example
broadcast
broadcast
operation
None
a

10) If you try to acces the column which does not exit, system throws
a)
NullPointerException
b)
illegalArgumentException
c)
ArrayIndexOutOfBoundsException
30 | P a g e

d)

SQLException

Ans:
11)

b
Maximum

results

returned

by

getFromLocationName()

method

can

be

a)
b)
c)
d)

2
3
4
5

Ans:

12. The methods startForeground() and stopForeground() were introduced in which


API
level.
a)
b)
C)
d)

2.0
3.0
1.5
2.2

Ans:

13. Should always first check availability of audio effects by calling the following method
on
the
a)
b)
c)
d)
Ans:

corresponding

audio

isvaluable

effect

class.
ischeckable()
isavailable()
()
iscaview()
a

14. Applications that require filtering based on screen size can use the attributes.
a)
31 | P a g e

<supportmultiple-screens>

b)
c)
d)

<supports-screens>
<supportall-screens
supportevery-screen

Ans:

15.
a)
b)
c)
d)

what

is

false

with

respect

to

onBind()

is

called when another component wants to bind with a service


calling
startService()
results
in
a
call
to
onBind()
if
you
don't
want
to
allow
binding
then
return
null
if
you
want
to
allow
binding
then
return
Ibinder
object

Ans:

16)Android is licensed under which open source licensing license? | Android


A.
B.
C.
D.
Ans:

Gnu's

GPL
Apache/MIT
OSS
Sourceforge
B

17)Although most people's first thought when they think of Android is Google, Android
is not actually owned by Google. Who owns the Android platform? | Android
A.
B.
C.
D.

Oracle

The

above

Open
statement

is

and

Handset
Android
is

owned

Ans:

Technology
Dalvik
Alliance
by Google
C

18)As an Android programmer, what version of Android should you use as your
minimum
development
target?
|
Android
A.
B.
32 | P a g e

Versions
Versions

1.6
1.0

or
or

2.0
1.1

C.
D.

Versions
Versions

1.2
2.3

or
or

1.3
3.0

Ans:

19)What was Google's main business motivation for supporting Android? | Android
A.
To
level
the
playing
field
for
mobile
devices
B.
To
directly
compete
with
the
iPhone
C. To corner the mobile device application market for licensing purposes
D.
To
allow
them
to
advertise
more
Ans:

20)What was the first phone released that ran the Android OS? | Android
A.
B.
C.
D.

Google
T-Mobile
Motorola
HTC

gPhone
G1
Droid
Hero

Ans:

21)From a phone manufacturer's point of view, what makes Android so great? | Android
A. Aside from some specific drivers, it provides everything to make a phone work
B.
It
makes
the
hardware
work
better
C.
It
allows
them
to
compete
with
Apple's
iPhone
D. It allows users to create apps, generating revenue for the companies
Ans:
22)What

A
is

funny

fact

about

the

start

of

Android?

Android

A.
It
was
orginaly
going
to
be
called
UFO
B. The first version of Android was released without an actual phone on the market
C. Androids main purpose was to unlock your car door when you left the keys inside of
it.
D. Was going to be a closed source application to make more money for its company.
33 | P a g e

Ans:

23)What

year

was

the

Open

Handset

Alliance

announced?

A.
B.
C.
D.

Android
2005
2006
2007
2008

Ans:

24)A device with Android installed is needed to develop apps for Android.
A.
B.

True
False

Ans:

25)Android tries hard to _____low-level components, such as the software stack, with
interfaces
so
that
vendor-specific
code
can
be
managed
easily.
A.
B.
C.
D.

confound
absract
modularize
compound

Ans:

26)Google

licensed

some

proprietary

apps.

Android

A.
B.

True
False

Ans:

27)What
A.
B. all
C.

part

of

34 | P a g e

these

of

the

Android

low-level
answers #The

platform

entire
native

is

open

Linux
stack is an

source?

open

Android

source

modules
platform
libraries

D.
E.

application
complete

frame

work
applications

Ans:

28)When

did

Google

purchase

Android?

ANdroid

A.
B.
C.
D.

2007
2005
2008
2010

Ans:

29)Android releases since 1.5 have been given nicknames derived how? | Android
A.
B.
C.
D.

Adjective
Something

that

and

starts

w/

strange

'A' ->
American

Something

that

animal
Food
w/ 'B'...
states

starts

Ans:

30)Which
A.
B.
C.
D.
Ans:

one

is

not

nickname

of

version

of

Andriod?

Android

cupcake
Gingerbread
Honeycomb
Muffin
D

31)Android doesn't make any assumptions about a device's screen size, resolution, or
chipset.:
A.
B.
Ans:
35 | P a g e

True
False
A

32)Which Android version had the greatest share of the market as of January 2011? |
Android
A.
B.
C.
D.

1.1
1.5
2.3
3.4

Ans:

33)Which piece of code used in Android is not open source? | Android


A.
B.
C.
D.

Keypad
WiFi?
Audio
Power

Ans:

driver
driver
driver
management

34)Android is built upon the Java Micro Edition (J2ME) version of Java. | Android
A.
True
B.
False
Ans:

35)Which among these are NOT a part of Android's native libraries? | Android
A.
B.
C.
D.

Webkit
Dalvik
OpenGL
SQLite

Ans:

36)Android
A.
B.
36 | P a g e

is

based

on

Linux

for

the

following

reason.

Android
Security
Portability

C.
D.
Ans:

All

of

Networking
these

37)What operating system is used as the base of the Android stack? | Android
A.
B.
C.
D.
Ans:

Linux
Windows
Java
XML
A

38)What year was development on the Dalvik virtual machine started? | Android
A.
B.
C.
D.
Ans:

2003
2005
2007
2006
B

39)What is a key difference with the distribution of apps for Android based devices than
other
mobile
device
platform
applications?
|
Android
A.
Applications
are
distributed
by
Apple
App
Store
only
B.
Applications are distributed by multiple vendors with different policies on
applications.
C. Applications are distributed by multiple vendors with the exact same policies on
applications.
D.
Applications
are
distributed
by
the
Android
Market
only.
Ans:
B

40)When developing for the Android OS, Java byte code is compiled into what? |
Android
37 | P a g e

A.
B.
C.
D.
Ans:

Java
Dalvik
Dalvik
C

source
application
byte
source

code
code
code
code

41)What

does

A.
B.
C.
D.
Ans:

the

.apk

extension

stand

for?

Application
Application
Android

Program
Proprietary
Android

Android
Package
Kit
Kit
Package

42)When you distribute your application commercially,you'll want to sign it with your
own
key.
|
Android
A.
B.
Ans:

True
False
A

43)How does Google check for malicious software in the Android Market? | Android
A.
B.
C.
D.
Ans:

Every
new
app
is
scanned
by
a
virus
scanner
Users
report
malicious
software
to
Google
Google
employees
verify
each
new
app
A seperate company monitors the Android Market for Google
B

44)Which of these are not one of the three main components of the APK? | Android
A.
B.
C.
D.
Ans:

Dalvik
Native

Executable
Resources
Libraries
Webkit
D

45)What is the name of the program that converts Java byte code into Dalvik byte code?
|
Android
38 | P a g e

A.
B.
C.
D.
Ans:

Android

Interpretive
Dalvik
Dex
Interpretive

Mobile

Compiler

(AIC)
Converter
compiler
(MIC)

Compiler

46)Android

Applications

A.
B.
C.
D.
Ans:

must

After
Before
Within

be

signed.

they
they
two

Android

are
are

weeks

installed
installed
Never
installation

of

47)Which of the following are not a component of an APK file? | Android


A.
B.
C.
D.
Ans:

All

of

these

are

components
Native
Dalvik

of

Resources
the
APK
Libraries
executable

48)The AWT and Swing libraries have been removed from the Android library set. |
Android
A.
B.
Ans:

True
False
A

49)The R.java file is where you edit the resources for your project. | Android
A.
B.
Ans:
50)What

A.
B.
39 | P a g e

True
False
B
is

contained

The
The

list

within

the

manifest

permissions
of
strings

xml

the
used

file?

app
in

Android

requires
the
app

C.
D.
Ans:

The
All

code
choices

51)What
A.
B.
C.
D.
Ans:

source
other

is

contained

within

the

Layout

xml

file?

Android

Orientations and layouts that specify what the display looks like.
The
permissions
required
by
the
app.
The
strings
used
in
the
app.
The
code
which
is
compiled
to
run
the
app.
A

52)The

emulated

device

for

android.

Android

A. Runs the same code base as the actual device, all the way down to the machine
layer.
B. Is more of a simulator, and acts as a virtual machine for the Android device.
C.
Runs the same code base as the actual device, however at a higher level.
D.
An imaginary machine built on the hopes and dreams of baby elephants.
Ans:
A
53)Your Java source code is what is directly run on the Android device. | ANdroid
A.
B.
Ans:

True
False
B

54)The Emulator is
emulating/simulating
A.
B.
C.
D.
Ans:

identical

to running
what?

The emulator can emulate/simulate all


C

55)How
40 | P a g e

is

simulator

different

from

real

phone
|

aspects of

an

EXCEPT when
Android
Telephony
Applications
Sensors
a smart phone.

emulator?

Android

A. Emulators are only used to play old SNES games, simulators are used for software
development
B. The emulator is shipped with the Android SDK and third party simulators are not
C.
The emulator can virtualize sensors and other hardware features, while the
simulator
cannot
D.
The emulator imitates the machine executing the binary code, rather than
simulating
the
behavior
of
the
code
at
a
higher
level.
Ans:
D
56)

The

file

is

A.
B.
C.
D.
Ans:
57)An

a(an)

generated

None

activity

can

A.
B.
C.
D.
Ans:

be

thought

of

of

as

file

the

corresponding

A
A
A
An

to

Android

Automatically
Manually
Emulated
above
A

what?

Java
Java
method
object

Android
project
class
call
field

58)To create an emulator, you need an AVD. What does it stand for? | Android
A.
B.
C.
D.
Ans:
59)The
A.
B.
Ans:
41 | P a g e

Android
Android
Active
Application

Virtual
Virtual
Virtual
Virtual

Display
Device
Device
Display

B
Android

SDK

ships

with

an

emulator.

Android
True
False

60)The ___________ file specifies the layout of your screen. | Android


A.
B.
C.
D.
Ans:

Layout
Manifest
Strings
R

file
file
XML
file

61)The manifest explains what the application consists of and glues everything together.
|
Android
A.
B.
Ans:

True
False
A

62)The Android Software Development Kit (SDK) is all you need to develop
applications
for
Android.
A.
B.
Ans:

True
False
A

63)What is the driving force behind an Android application and that ultimately gets
converted
into
a
Dalvik
executable?
|
Android
A.
Java
source
code.
B.
R-file.
C.
the
emulator.
D.
the
SDK
Ans:
A
64)While developing Android applications, developers can test their apps on...
A.
B.
C.
D.
Ans:
65) How can
42 | P a g e

Emulator

included
in
Android
Physical
Android
Third-party
Emulators
(Youwave,
All
three
options
will
D

SDK
phone
etc.)
work.

I check if an activity is already running before starting it?

A.
NEW_TASK_LAUNCH
in
the
startActivity()
method
call.
B.
FLAG_ACTIVITY_NEW_TASK in
the
startActivity()
method
call.
C.
FLAG_ACTIVITY_SINGLE_TOP in
the
startActivity()
method
call.
D.
By
using <category android:name="android.intent.category.LAUNCHER" />
this category attribute.

43 | P a g e

You might also like