Android Development

Published on February 2017 | Categories: Documents | Downloads: 46 | Comments: 0 | Views: 367
of 43
Download PDF   Embed   Report

Comments

Content

 

 Android: Android  Android:  Android is an open-source software stack that includes the operating 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 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 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 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.  OS.  Powerful development framework: Easily optimize a single binary for phones, tablets, and other devices.  devices.  Open marketplace for distributing apps: Google 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.  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: fol lowing:  

   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 platforms don't have?  have?  Q. What Android has that other platforms 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 applications— applications—Google Maps for Mobile has been hugely popular, and  Android offers a Google Map as an atomic, reusable control for use in your applications. applications. Background services and applications— applications—Full 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— communication—  Using Intents and Content Providers, Android lets your applications exchange messages, perform processing, and share data.  All applications are created equal— equal— Android doesn't differentiate between native applications and those developed by third parties.  Wi-Fi Direct and Android Beam— Beam—Using 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 box— box —Using  Widgets and Live Live   Wallpaper, you can create windows into your  your  application from the phone's home screen. The quick   search box lets you integrate search results from your  your   application directly into the phone's search  search  functionality. functionality.    Android Application Architecture 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 Manager— —  Control the lifecycle of your Activities and Fragments, respectively, including management of the Activity stack (described in Chapters 3 and 4).  Views—  Views —Used to construct the user interfaces for your Activities and Fragments, as described in Chapter 4. 3|Page 

 

Notification Manager— Manager—Provides a consistent and nonintrusive mechanism for signalling your users, as described in Chapter 10. Content Providers— Providers—Lets your applications share data, as described in Chapter 8. Resource Manager— Manager—Enables non-code resources, such as strings and graphics, to be externalized, as shown in Chapter 3. Intents— Intents —Provides 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: Foreground— Foreground — An 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. Background— Background — An 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. Intermittent—Most well-designed applications fall into this category. At one extreme Intermittent— 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 applications are great examples.  Widgets and Live Wallpapers— Wallpapers—Some 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 don’t have a real device for experimentation.  experimentation.   Android applications  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:  Activities— Your application's presentation layer. The UI of your application is built  Activities— 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. Services— Services —The invisible workers of your application. Service components run without a UI, updating your data sources and Activities, triggering Notifications, and  broadcasting Intents. They're T hey'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 Providers— Providers—Shareable 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.” Intents— Intents — A 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 Receivers— Receivers—Intent 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.  Widgets—  Widgets — Visual 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.”   Screen.” Notifications— Notifications —Notifications 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 applications applications— — both your own and those of third third parties.

 Android questions and Answers

1.

bmgr

a)take

tool

backup

is of

 b)to

used the

applications

restore

c)wipe

archived

data

to operations

for

a

specific

application

d)all of the above

ans:

d

2.

foreground

a)starts  b)may

when or

may

you not

provide

call a

notification

service start for

foreground() the

status

bar

c)notification can't be dismissed unless the service is either stopped or removed from the 6|Page 

 

foreground d)both

a

&

c

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 FLAG_ACTIVITY_NO_HISTORY.When finish method is ccalled alled on A3, What  will currtent

be running

the activity?

a)A1  b)A4 c)A3 d)A2 ans:

b

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 current

be running

the activity?

a)A4  b)A3 c)A2 d)A1  Ans:

a

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.

b

The

a)  b) c)

plus(+)

means

Identify Create XML

it new

parser

d)

in

statement as

id

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

an and

should

add

parse

Both

id to

and

resource resources

exapnd

a

id

&

string b.

 Ans:

b

7. When you want system to run the service indefinitely, by restarting it when get killed, use a)  b)

START_NOT_STICKY START_REDELIVER_INTENT START_REDELIVER_INTEN T

c)

START_STICKY

d)

START_SERVICE_INDEFINITELY

 Ans:

c

8)

Android

system

uses

intents

to

a)

broadcast

system

intents

 b)

broadcast

custom

intents

c) d)

To

invoke All

other

applications of

from the

your

 Ans: 9)

application. above. d

'Screen

has

turned

off'

is

an

example

a)  b)

Normal Ordered

broadcast broadcast

c) d)

background

operation None

8|Page 

 

 Ans:

a

10) If you try to acces the column which does not exit,

system throws

a)

NullPointerException

 b)

illegalArgumentException

c) d)

ArrayIndexOutOfBoundsException SQLException

 Ans: 11)

b Maximum

results

returned

by

getFromLocationName()

method

can

be

a)

2

 b)

3

c) d)

4 5

 Ans:

d

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

level.

a)

2.0

 b)

3.0

C)

1.5

d)

2.2

 Ans:

a

13. Should always first check availability of audio effects by calling the following method on the

corresponding

audio

effect

class.

a)

ischeckable()

 b) c)

isavailable() ()

9|Page 

isvaluable

 

d)

iscaview()

 Ans:

a

14. Applications that require filtering based on screen size can use the attributes.

a)  b)

<supportmultiple-screens> <supports-screens>

c) d)

<supportall-screens supportevery-screen

 Ans:

b

15. a)  b)

what is

c) d)

called calling

if if

you you

is

false

when another startService() don't want

with

respect

component results

wants to in a

want to allow to allow binding

to bind call

with to

onBind() a

service onBind()

binding then return null 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) d)None

security of

sandbox the

 Ans) 2)Parent a)Object  b)Context c)ActivityGroup d)ContextThemeWrapper 10 | P a g e  

above c

class

of

Activity?

 

 Ans) 3)What

d are

the

Direct

subclasses

of

Activity?

a)AccountAuthenticatorActivity  b)

ActivityGroup

c)

ExpandableListActivity

d) e)

FragmentActivity ListActivity

f)  Ans) 4)What

all

are

the

the

indirect

Direct

aove f

subclasses

of

Activity?

a)LauncherActivity  b)PreferenceActivity c)

TabActivity

d)All  Ans)

the

5)Parent a)Object

above d

class

of

Service?

 b)Context c)

ContextWrapper

d)ContextThemeWrapper  Ans) 6)What

c are

the

indirect

Direct

subclasses

of

Services?

a)

RecognitionService

 b)

RemoteViewsService

c)SpellCheckerService d)InputMethodService  Ans) 7)Which

component

is

not

activated

by

an

d Intent?

a)Activity  b)Services c)ContentProvider d)BroadcastReceiver  Ans) 8)When a)Using  b)Using c)Using 11 | P a g e  

c contentProvider

would

be

activated? Intent SQLite ContentResolver

 

d)None

of

the

above

 Ans)

c

9)Which of the important device characteristics characteristics that you should consider as you design and

develop

a)Screen

your

size

application?

and

density

 b)Input

configurations

c)Device d)Platform

features Version

e)All  Ans)

of

10)Which

are

the

the

screen

above e

sizes

in

Android?

a)small  b)normal c)large d)extra

large

e)All  Ans)

of

11)Which a)low

are

the

the

screen

above e

densities

in

Android? density

 b)medium

density

c)high

density

d)extra

high

e)All  Ans)

density

of

12)You

can

shut

down

the an

activity

by

above e

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) 14)Which 12 | P a g e  

one

is

NOT

related

to

fragment

a class?

 

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 a)They

of

are

 b)They

available

the

to

provide

every

Loaders?

Activity

asynchronous

and

loading

Fragment. 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 e)All

change.

Thus, of

they

don't

need to the

re-query

 Ans)

their

data. above. e

17)How

many

ways

to

start

services?

a)Started  b)Bound c)a

&

d)None

of

b 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

d)None

 b)

Binder

c)

AIDL 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)

b

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 a

 Ans) 21)Layouts a)Frame

in

android? Layout

 b)Linear

Layout

c)Relative

Layout

d)Table

Layout

e)All

of

the

above

 Ans) 22)

e 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  Ans) 24)Difference

between

android

provider api

and

google

d 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 c)None

and

other of

Google-specific the

libraries. above.

 Ans) a  Android: Menus and Dialogs

Table 1. 1.  Menus  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 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 2 3

public public

public

boolean boolean

onCreateOptionsMenu(Menu onCreateOptionsMenu(Menu

menu)

onPrepareOptionsMenu(Menu

menu)

boolean onOptionsItemSelected(MenuItem 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 /* public

Menu Creates

the

boolean

Example: menu

items

onCreateOptionsMenu(Menu

menu)

*/ {

menu.add(0,

1,

0,

"Menu

1");

menu.add(0,

2,

0,

"Menu

2");

return } /* 18 | P a g e  

true; Handles

item

selections

*/

 

public

boolean

onOptionsItemSelected(MenuItem

switch

item)

{

(item.getItemId())

case

1:

//Action

{

for

Menu

1

return

true;

case

2:

//Action

for

Menu

2

return

true;

} return

false;

}

/*

Re-write

public //Action

the

Options

boolean to

SubMenu

Menu

as

it

is

onPrepareOptionsMenu(Menu

modify

Menu

sm1

each =

time

opened menu)

it

is

*/ {

opened.

(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, 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

/*

Register

a

Example: view

to

public void onCreate(Bundle super.onCreate(savedInstanceState); Button

update

*/

savedInstanceState){

=

new

Button(this);

update.setText(“UPDATE”);  update.setText(“UPDATE”);  setContentView(update); registerForContextMenu(update); } /*

Create

a

Context

Menu

*/

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)

{

super.onCreateContextMenu(menu,

v,

menu.add(0, menu.add(0,

0, 0,

1, 2,

menuInfo); "Edit"); "Delete");

} /*

Action

public

boolean

on

1:

//Action

case

2:

//Action

return

} 22 | P a g e  

for for

menu Menu

*/ item)

(item.getItemId())

case return

}

selection

onContextItemSelected(MenuItem

switch

default:

item

{ {

item item

“Edit”   “Edit” true; “Delete”   “Delete”  true;

return

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 item is a radio button or checkbox.

Dialog:

 A dialog is a small window that appears in front of an 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

Alert

Dialog

Progress

Dialog

3

Date

Picker

Dialog

4

Time 5

Picker

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. 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. date. TimePicker Dialog  A dialog that allows the user to select a time.

Toast:

 A toast is a transient Dialog box containing containing a quick little message for the user. Toasts never receive focus and they don’t interrupt the active application.  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 d isplay 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.  Activity provides following methods to create and 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)

protected

Dialog

to

create

a

onCreateDialog(int

dialog

id)

{

switch(id){ case

DIALOG_ALERT_ID:

//Create

required

case //Create

dialog

required

dialog

and

return

and

DIALOG_DISP: return object

case

object

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 protected

onPrepareDialog() void

onPrepareDialog(int

super.onPrepareDialog(id, 25 | P a g e  

to

modify id,

Dialog

a

dialog dialog)

{

dialog);

 

switch(id)

{

case

DIALOG_ALERT_ID:

//Modify

in

dialog

and

break;

case

DIALOG_DISP:

//Modify

in

dialog

and

case

break;

DIALOG_PROGRESS:

//Modify default

in

dialog

and

break; :

 break; } } Create

Alert

Create a dialog  AlertDialog.Builder

builder using builder

Set all required  builder.setMessage(“message

Dialog:

AlertDialog.Builder by passing context. = new AlertDialog.Builder(this);

properties

for

the

created

to

.setTitle(“title

to

builder. display”)  display”)  display”)  display”) 

.setCancelable(false); //Can

set

different

setPositiveButton("Yes", //override onClick()

buttons

here

new DialogInterface.OnClickListener() { and perform required operation like finish()

} setNegativeButton("No", //override

onClick()

}) Retrieve

the

new and

Alert

 AlertDialog

ProgressDialog

perform

required

dialog

object

alertObj

Create

Create

DialogInterface.OnClickListener() operation with

=

like

builder.create(); Dialog:

progress progress

=

dialog new

26 | P a g e  

Please

object

ProgressDialog(mContext);

Set all the required properties and progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setTitle("Loading..."); progress.setMessage("Loading.

cancel()

builder.create().

Progress

a

{

return

wait...");

 

progress.setCancelable(false); Create

the

object

ProgressDialog

by

its

dialog

"Loading.

show()

=

method,

set

shown

ProgressDialog.show(this,

Please

//Can

as

"Loading...",

wait...",

other

below. true);

properties

here

also

dialog.setCancelable(true); dialog.setIcon(R.drawable.icon); Create

Time

Picker

Dialog:

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

below.

//Get

the

final

Calendar

c

mHour mMinute //Create return public

current =

=

new void

return the TimePickerDialog(this,

onTimeSet(TimePicker

//Perform

TimePickerDialog object new OnTimeSetListener() {

view,

operation

}},

int

hourOfDay,

on

mHour,

Create

Calendar.getInstance(); c.get(Calendar.HOUR_OF_DAY); c.get(Calendar.MINUTE);

= and

Time

int

time

minute)

{ set

mMinute,

true);

picker

dialog:

Date

Create a DatePickerDialog object by passing context and other parameters, as shown  below. //Get final mYear

the Calendar

c

mMonth mDay //Create

current =

=

Calendar.getInstance(); c.get(Calendar.YEAR);

=

c.get(Calendar.MONTH);

= and

Date

return

c.get(Calendar.DAY_OF_MONTH); the

DatePickerDialog

object

return new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { public int //Perform } }, 27 | P a g e  

void

onDateSet(DatePicker

monthOfYear, operation mYear,

view,

int on mMonth,

int

dayOfMonth) date

year, { set mDay);

 

Create

Toast:

Create

a

Toast

Toast

t

object =

with

new

t.setText("Dialog t.setGravity(Gravity.LEFT, a

duration

Displayed 10, 100);

Toast

context.

Toast(getApplicationContext());

Set properties like text, t.setDuration(Toast.LENGTH_LONG);

Display

application

and

from //Position, xOffset

using

its

show()

method

makeText()

position. Toast"); yOffset

and

method.

t.show(); Create Toast

directly t

=

using

its

static

Toast.makeText(getApplicationContext(),

as

below.

"Dialog

Displayed",

used

to

Toast.LENGTH_SHOT);

 Android Questions and Answers for written exams exams

1.

bmgr

a)take

tool

backup

is of

 b)to

the

applications

restore

c)wipe

archived

d)all

data

operations

for

a

of

specific the

above

ans:

d

2. a)starts  b)may

application

foreground or

when may not

you provide

a

service

call start notification for

the

foreground() status bar

c)notification can't be dismissed unless the service is either stopped or removed from the foreground d)both

a

&

c

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 FLAG_ACTIVITY_NO_HISTORY.When finish method is called on A3, What  will

be

currtent

running

the activity?

a)A1  b)A4 c)A3 d)A2 ans:

b

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

current

running

the activity?

a)A4  b)A3 c)A2 d)A1  Ans:

a

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)

Identify

it

Create XML

new parser

d)

as id

an and

should

add

parse

Both

id

and

resource

to

resources

exapnd

a

id

&

string b.

 Ans:

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:

c

8)

Android

system

uses

intents

to

a)

broadcast

system

intents

 b)

broadcast

custom

intents

c) d)

To

invoke All

other

applications of

from the

your

 Ans:

9)

application. above. d

'Screen

has

turned

off'

is

an

example

a)  b)

Normal Ordered

broadcast broadcast

c)

background

operation

d)  Ans:

None a

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

illegalArgumentException ArrayIndexOutOfBoundsException

 

d)

SQLException

 Ans: 11)

b Maximum

results

returned

by

getFromLocationName()

method

can

be

a)  b)

2 3

c) d)

4 5

 Ans:

d

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

level.

a)

2.0

 b)

3.0

C)

1.5

d)

2.2

 Ans:

a

13. Should always first check availability of audio effects by calling the following method on the

corresponding

audio

effect

class.

a)

ischeckable()

 b)

isavailable()

c) d)  Ans:

isvaluable

() iscaview() a

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

<supportmultiple-screens>

 

 b)

<supports-screens>

c)

<supportall-screens

d)

supportevery-screen

 Ans:

b

15. a)  b)

what is

called calling

c)

if

you

d)

if

you

is

false

when another startService() don't want

with

component results

want to

respect

to

allow

wants to in a

allow binding

bind call

binding then

to with to

then

return

onBind() a

service onBind()

return Ibinder

 Ans:

null object b

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

Gnu's

GPL

B.

Apache/MIT

C.

OSS

D.  Ans:

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.

Oracle

B. C. D.

Technology

Open The

above

statement statement

Dalvik Alliance

Handset is

and

Android

is

owned

 Ans:

by

Google C

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

development Versions Versions

target? 1.6 1.0

|

Android

or or

2.0 1.1

 

C.

Versions

1.2

or

1.3

D.

Versions

2.3

or

3.0

 Ans:

A

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:

D

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

Google

B.

gPhone

T-Mobile

G1

C.

Motorola

Droid

D.

HTC

Hero

 Ans:

B

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:

A

22)What  A.

It

is

a was

funny

fact orginaly

about

the

going

start to

of

Android? be

|

Android

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:

B

23)What

year

was

the

Open

Handset

Alliance

announced?

|

Android

 A.

2005

B.

2006

C. D.

2007 2008

 Ans:

C

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

True

B.

False

 Ans:

B

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.

confound

B. C.

absract modularize

D.

compound

 Ans:

B

26)Google

licensed

some

proprietary

apps.

|

Android

 A.

True

B.

False

 Ans:

A

27)What

part

 A. B. C.

of

the

Android

platform

low-level all

of

34 | P a g e  

these

answers

#The

is

open

source?

|

Linux entire native

stack

is

an

Android modules

open

source

platform libraries

 

D.

application

E.

frame

work

complete

applications

 Ans:

B

28)When

did

Google

purchase

Android?

|

ANdroid

 A.

2007

B. C.

2005 2008

D.

2010

 Ans:

B

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

Adjective

and

strange

animal

B. C.

Food Something

that

starts

D.

w/

'A'

->

Something

that

starts

w/

American

states

 Ans:

30)Which

'B'...

B

one

is

not

a

nickname

of

a

version

of

Andriod?

|

Android

 A.

cupcake

B. C.

Gingerbread Honeycomb

D.

Muffin

 Ans:

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.

1.1

B.

1.5

C.

2.3

D.

3.4

 Ans:

B

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

Keypad

driver

B.

WiFi?

driver

C. D.

Audio Power

driver management

 Ans:

B

34)Android is built upon the Java Micro Edition (J2ME) version of Java. | Android  A.

True

B.

False

 Ans:

B

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

Webkit

B. C.

Dalvik OpenGL

D.

SQLite

 Ans:

36)Android

B

is

based

on

Linux

for

the

following

reason.

|

Android

 A.

Security

B.

Portability

36 | P a g e  

 

C.

Networking

D.

All

of

 Ans:

these

D

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

Linux Windows

C.

Java

D.

XML

 Ans:

A

38)What year was development on the Dalvik virtual machine started? | Android  A.

2003

B.

2005

C.

2007

D.

2006

 Ans:

B

39)What is a key difference with the distribution of apps for Android based devices than other

mobile

 A.

Applications

device

platform

are

distributed

applications? by

Apple

| App

Android Store

only

B. Applications are distributed by multiple vendors with different policies on applications. C.

Applications are distributed distributed by multiple multiple vendors with the exact same policies policies on

applications. D.

Applications

 Ans:

are

distributed

by

the

Android

Market

only.

B

40)When developing for the Android OS, Java byte code is compiled into what? |  Android

37 | P a g e  

 

 A.

Java

B.

Dalvik

C.

source

code

application

code

Dalvik

D.

byte

C

code

source

 Ans:

code

C

41)What

does

the

.apk

extension

 A. B.

Application

C.

Android

stand

for?

|

Android

Application

D.

Program

Package Kit

Proprietary

Kit

Android

 Ans:

Package

A

42)When you distribute your application commercially,you'll want to sign it with your own

key.

|

Android

 A.

True

B.

False

 Ans:

A

43)How does Google check for malicious software in the Android Market? | Android  A.

Every

B.

Users

C. D.

new

Google A

 Ans:

seperate

app report

is

scanned malicious

employees company

by

software

verify

monitors

the

a

virus

scanner

to

Google

each

Android

Market

new

app

for

Google

B

44)Which of these are not one of the three main components of the APK? | Android  A.

Dalvik

B. C. D.  Ans:

Executable Resources

Native

Libraries Webkit D

45)What is the name of the program that converts Java byte code into Dalvik byte code? |

38 | P a g e  

Android

 

 A.

Android

Interpretive

Compiler

(AIC)

B.

Dalvik

Converter

C.

Dex

compiler

D.

Mobile

 Ans:

Interpretive

Compiler

(MIC)

C

46)Android

Applications

 A. B.

must

be

After Before

signed.

they they

|

Android

are are

installed installed

C.

Never

D.

Within

two

weeks

 Ans:

of

installation

B

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

Resources

B.

All

of

these

are

components

C.

of

the

Native

D.

Libraries

Dalvik

 Ans:

APK

executable

B

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

True

B.

False

 Ans:

A

49)The R.java file is where you edit the resources for your project. | Android  A.

True

B.

False

 Ans: 50)What

B is

contained

 A. B. 39 | P a g e  

The The

within

the

manifest

permissions list

of

strings

xml

the used

file?

|

app in

Android

requires the

app

 

C.

The

D.

All

 Ans:

code

other

choices

A

51)What  A.

is

contained

Orientations

B. C.

and

The The

D.

The

within layouts

the that

Layout

specify

permissions strings

code

 Ans:

which

is

xml

what

file?

the

required used

in

compiled

to

|

Android

display

by

looks

the the run

like. app. app.

the

app.

A

52)The

 A.

source

emulated

device

for

android.

|

Android

Runs the same code base as the actual device, all the way down to the machine

layer. B.

Is more of a simulator, and and acts as a virtual machine for the 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.

True

B.  Ans:

False B

54)The

Emulator

is

identical

emulating/simulating

to

running

a

real

what?

phone

EXCEPT

|

when

Android

 A.

Telephony

B.

Applications

C.

Sensors

D.  Ans:

The

55)How 40 | P a g e  

is

emulator can

a

simulator

emulate/simulate all C different

from

aspects

an

of

a

emulator?

smart

|

phone.

Android

 

 A.

Emulators are only used to play old SNES games, simulators are used for software

development B.

The emulator emulator is shipped with 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: 56)

D The

R

file

is

a(an)

generated

file

|

Android

 A.

Automatically

B.

Manually

C.

Emulated

D.  Ans: 57)An

None

activity

can

be

thought

 A.

of

of

as

the

corresponding

A

to

above A

what?

Java

|

Android project

B.

A

Java

class

C. D.

A An

method object

call field

 Ans:

B

58)To create an emulator, you need an AVD. What does it stand for? | Android  A.

Android

Virtual

Display

B. C.

Android Active

Virtual Virtual

Device Device

D.

Application

Virtual

Display

 Ans: 59)The

B Android

SDK

ships

with

 A. B.  Ans:

41 | P a g e  

an

emulator.

|

Android True False

A

 

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

Layout

file

B.

Manifest

file

C.

Strings

XML

D.

R

file

 Ans:

A

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

True

B.

False

 Ans:

A

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

True

B.

False

 Ans:

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

D.  Ans:

emulator. the

A

SDK

64)While developing Android applications, developers can test their apps on...  A.

Emulator

B. C. D.  Ans: 65) How can

42 | P a g e  

included

in

Physical Third-party All

Android Android

Emulators three

options

SDK phone

(Youwave, will

etc.) work.

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

 

 A.

NEW_TASK_LAUNCH

B.

FLAG_ACTIVITY_NEW_TASK in

C.

FLAG_ACTIVITY_SINGLE_TOP FLAG_ACTIVITY_SINGLE_TOP in

D.

B y

the

startActivity()

the the

method

call.

startActivity()

method

call.

startActivity()

method

call.

using <category  android:name= android:name="android.intent.category.LAUNCHER" "android.intent.category.LAUNCHER"  />

this category attribute.  attribute. 

43 | P a g e  

in

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close