1. 2. 3. 3.1. 3.1.1. 3.2. 3.2.1. 3.2.2. 3.3. 3.4. 3.5. 4. 4.1. 4.2. 4.2.1. 4.2.2. 4.2.3. 4.2.4. 4.3. 4.3.1. 4.3.2. 4.4. 4.4.1. 4.4.2. 5. 6. 6.1. 6.2. 7. What is Android ? ..................................................................................... 1 What are the features of Android Platform ? .................................................... 1 What is the Architecture of Android ? ............................................................ 1 Linux Kernel ............................................................................................ 2 Key Points:.............................................................................................. 2 Android Runt ime & Core API s ....................................................................... 2 Android Runtime ....................................................................................... 2 Core APIs ................................................................................................ 2 Libraries................................................................................................. 2 Application Framework ............................................................................... 3 Applications ............................................................................................ 3 Android Applications ................................................................................. 3 Fundamentals .......................................................................................... 3 Application Components ............................................................................ 2 Activity .................................................................................................. 3 Services ................................................................................................. 3 Broadcast Receivers ................................................................................... 4 Content Providers ..................................................................................... 4 Activating & Shutdown Components ................................................................ 4 Activating Components: Intents ..................................................................... 4 Shutting Down Components .......................................................................... 5 Others ................................................................................................... 5 The Manifest file ....................................................................................... 5 Intents, Intent Objects and Intent filters .......................................................... 6 Activities & Tasks ..................................................................................... 9 Processes and Threads............................................................................. 10 Process ................................................................................................. 10 Threads ................................................................................................ 11 Switching to Home Screen ........................................................................ 11
List of Figures
Figure 1. Figure 2. Figure 3. Figure 4. Figure 5. Architecture of Android Operating System Building blocks of an Application Boot up process Boot up Process - 2 Home Screen Launching Process 2 2 11 12 13
List of Tables
Table 1. Table 2. Action Constants ................................................................................... 7 Category Constants ................................................................................ 8
Confidential
ii
Version
1. What is Android ?
Android is a soft ware st ack for mobile devices t hat includes an operat ing syst em, middleware and key applications. The Android SDK provides t he t ools and APIs necessary t o begin developing applicat ions on t he Android platform using the Java programming language.
Confidential
Version
Figure 1.
3.3. Libraries
Set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework - System C library - a BSD-derived implement at ion of t he st andard C syst em library (libc), t uned for embedded Linux-based devices - Media Libraries - based on Packet Video's OpenCORE; t he libraries support playback and recording of many popular audio and video format s, as well as st at ic image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
Confidential 2 Version
Surface Manager - manages access t o t he display subsyst em and seamlessly composit es 2D and 3D graphic layers from multiple applications LibWebCore - a modern web browser engine which powers bot h t he Android browser and an embeddable web view SGL - the underlying 2D graphics engine 3D libraries - an implement at ion based on OpenGL ES 1.0 APIs; t he libraries use eit her hardware 3D accelerat ion (where available) or t he included, highly opt imized 3D soft ware rasterizer FreeType - bitmap and vector font rendering SQLite - a powerful and lightweight relational database engine available to all applications
3.5. Applications
Applicat ions are t he general applicat ions t hat are pre shipped wit h t he phone or downloaded and installed from the market. Applications make use of Application Framework
4. Android Applications
4.1. Fundamentals
1. Android applications are written in the Java programming language. 2. The compiled Java code along wit h any dat a and resource files required by t he application is bundled by t he aapt tool int o an Android package, an archive file marked by an .apk suffix. 3. This file is used to install the applications on Android device 4. Each Android application lives in its own world: By default, every application runs in its own Linux process. Android st art s t he process when any of t he applicat ion's code needs t o be execut ed, and shut s down t he process when it 's no longer needed and syst em resources are required by other applications.
Confidential
Version
Each process has it s own virt ual machine (VM), so applicat ion code runs in isolat ion from the code of all other applications. By default, each application is assigned a unique Linux user ID. Permissions are set so t hat t he applicat ion's files are visible only t hat user, only t o t he application itself. There are ways to export them to other applications as well. It 's possible t o arrange for t wo applicat ions t o share t he same user ID, in which case they will be able to see each other's files. To conserve syst em resources, applicat ions wit h t he same ID can also arrange t o run in the same Linux process, sharing the same VM.
Figure 2.
Confidential
4.2.1. Activity
An activity presents a visual user interface for one focused endeavor the user can undertake. Though t hey work t oget her t o form a cohesive user int erface, each act ivit y is independent of the others. Each one is implemented as a subclass of the Activity base class. An application might consist of just one activity or it may contain several. Typically, one of t he act ivit ies is marked as t he first one t hat should be present ed t o t he user when t he applicat ion is launched. Moving from one act ivit y t o anot her is accomplished by having the current activity start the next one. Each activity is given a default window to draw in. Typically, t he window fills t he screen, but it might be smaller t han t he screen and float on t op of other windows. An act ivit y can also make use of addit ional windows window that presents users with vital information. for example, a pop-up dialog or a obj ect s derived from
The visual cont ent of t he window is provided by a hierarchy of views the base View class.
Each view cont rols a part icular rect angular space wit hin t he window. Parent views cont ain and organize t he layout of t heir children. Leaf views (t hose at t he bot t om of t he hierarchy) draw in the rectangles they control and respond to user actions directed at that space. Thus, views are where the activity's interaction with the user takes place. For example, a view might display a small image and init iat e an act ion when t he user t aps t hat image. Example of Views are but t ons, t ext fields, scroll bars, menu it ems, check boxes, and more. A view hierarchy is placed wit hin an act ivit y's window by the Activity.setContentView() met hod. The cont ent view is t he View obj ect at t he root of t he hierarchy.
4.2.2. Services
A service doesn't have a visual user int erface, but rat her runs in t he background for an indefinite period of time. For example, a service might play background music as the user attends to other matters Each service extends the Service base class. A prime example is a media player playing songs from a play list . The player applicat ion would probably have one or more act ivit ies t hat allow t he user t o choose songs and st art playing t hem. However, t he music playback it self would not be handled by an act ivit y because users will expect t he music t o keep playing even aft er t hey leave t he player and begin somet hing different . To keep t he music going, t he media player act ivit y could st art a service t o run in t he background. The syst em would t hen keep t he music playback service running even aft er t he activity that started it leaves the screen. It's possible t o connect t o (bind t o) an ongoing service (and st art t he service if it 's not already running). While connected, you can communicate with the service through an interface that the service exposes. Like act ivit ies and t he ot her component s, services run in t he main t hread of t he applicat ion process. So t hat t hey won't block ot her component s or t he user int erface, t hey oft en spawn another thread for time-consuming tasks (like music playback).
Confidential
Version
A service is st art ed (or new inst ruct ions are given t o an ongoing service) by passing an Int ent obj ect t o Context.startService(). Android calls t he service's onStart() met hod and passes it t he Intent object. Similarly, an int ent can be passed t o Context.bindService() t o est ablish an ongoing connect ion bet ween t he calling component and a t arget service. The service receives t he Int ent obj ect in an onBind() call. (If the service is not already running, bindService()can optionally start it.) For example, an act ivit y might est ablish a connect ion wit h t he music playback service ment ioned earlier so t hat it can provide t he user wit h t he means (a user int erface) for cont rolling t he playback. The act ivit y would call bindService() t o set up t hat connect ion, and then call methods defined by the service to affect the playback. An applicat ion can init iat e a broadcast by passing an Int ent obj ect t o met hods like Context.sendBroadcast(),Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() in any of t heir variat ions. Android delivers t he int ent t o all interested broadcast receivers by calling their onReceive() methods.
4.4. Others
4.4.1. The Manifest file
Describes the components that exist in an Android application Principal task of the Manifest file is to inform Android about the components of an Application Manifest file is also bundled into the application package (.apk file) Structured XML file which is named AndroidManifest.xml for all the applications.
4.4.1.1.
<manifest> [Root tag/node for the entire package] <uses-permission> [Security permissions required by the package to function correctly] <permission> [Permissions which are published by the package to restrict access for other ackages] <instrumentation> [Declares the availability of unit test code for the package] <application> [Contains all application level details. Only one application tag allowed in the file] <activity> [Facility to interact with the user, typically one screen, required for launching screens ] <intent-filter> [Declares the specific intents which the application supports] <action> [intent action ]
Confidential 5 Version
<category> [Intent category] <data> [data associated with intent eg. URI, MIME type etc] <meta-data> [Meta-data info which can be used by users of the app for data retrieval] <service> [Publishes service provided by the application ] <receiver> [List of external events information which the application requires ] <provider> [Publishes the data storage/retrieval capabilities of the application ]
4.4.1.2.
It names the Java package for the application. The package name serves as a unique identifier for the application. It describes the components of the application the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched. It determines which processes will host application components. It declares which permissions the application must have in order to access protected parts of the API and interact with other applications. It also declares the permissions that others are required to have in order to interact with the application's components. It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published. It declares the minimum level of the Android API that the application requires. It lists the libraries that the application must be linked against. Refer to this URL for more details on Android Manifest File: http://developer.android.com/intl/de/guide/topics/manifest/manifest-intro.html
4.4.2.1. 4.4.2.2.
An Intent Object is a bundle of information Cont ains informat ion t hat is usefull for t he component t hat receives t he int ent . Ex: Act ion t o be taken or Data to act on. Cont ains informat ion t hat is of int erest t o Android plat form. Ex: Cat egory of component and instructions to Launch Etc. An Intent object can contain any of the following:
Confidential 6 Version
4.4.2.2.2. Action
This is a string naming the Action to be performed In case of broadcast intents, the action that took place is reported You can define your own Act ion st rings. It should cont ain t he package name as prefix. Ex: com.example.project.SHOW_COLOR An Action in an Intent Object is set by the setAction() method and read by getAction() Few Action Constants that are already defined are shown in below table Constant ACTION_CALL ACTION_EDIT ACTION_MAIN ACTION_SYNC ACTION_BATTERY_LOW ACTION_HEADSET_PLUG ACTION_SCREEN_ON ACTION_TIMEZONE_CHANGED Target component activity activity activity activity broadcast receiver broadcast receiver broadcast receiver broadcast receiver Action Initiate a phone call. Display data for the user to edit. Start up as the initial activity of a task, with no data input and no returned output. Synchronize data on a server with data on the mobile device. A warning that the battery is low. A headset has been plugged into the device, or unplugged from it. The screen has been turned on. The setting for the time zone has changed.
4.4.2.2.3. Data
The URI of the data to be acted on and the MIME type of that data For example, if t he act ion field is ACTION_EDIT, t he dat a field would cont ain t he URI of t he document t o be displayed for edit ing. If t he act ion is ACTION_CALL, t he dat a field would be a tel: URI with the number to call.
Confidential
Version
The setData() met hod specifies dat a only as a URI, setType() specifies it only as a MIME t ype, andsetDataAndType() specifies it as both a URI and a MIME type. The URI is read by getData() and the type by getType().
4.4.2.2.4. Category
A st ring cont aining addit ional informat ion about t he kind of component t hat should handle t he intent. Addition of a Category to Intent Object by calling addCategory() function Removal of a Category from the Intent Object by calling removeCategory() function getCategories() to get the set of all the categories in the Intent Object Constant CATEGORY_BROWSABLE Meaning The target activity can be safely invoked by the browser to display data referenced by a link for example, an image or an e-mail message. The activity can be embedded inside of another activity that hosts gadgets. The activity displays the home screen, the first screen the user sees when the device is turned on or when the HOME key is pressed. The activity can be the initial activity of a task and is listed in the top-level application launcher. The target activity is a preference panel. Table 2. Category Constants
4.4.2.2.5. Extras
Key-value pairs for addit ional informat ion t hat should be delivered t o t he component handling the intent. Int ent Obj ect has a series of put () met hods and corresponding get .() met hods for insert ing and reading various types of extra data. Same as a bundle obj ect . Bundle can be insert ed int o Int ent Obj ect using put Ext ras() and read using getExtras().
4.4.2.2.6. Flags
Flags of various sort s. Many inst ruct t he Android syst em how t o launch an act ivit y (for example, which t ask t he act ivit y should belong t o) and how t o t reat it aft er it 's launched (for example, whether it belongs in the list of recent activities). All these flags are defined in the Intent class.
4.4.2.3.
Intent Resolution
Basically there are two types of Intents: o Explicit Intents: designate the target component by its name Typically used for applicat ion-int ernal messages such as an act ivit y st art ing a subordinate service or launching a sister activity Android delivers an explicit int ent t o an inst ance of t he designat ed t arget class. No special strategy is required
Confidential 8 Version
Implicit Intents: do not name a target Often used to activate components in other applications. In t he absence of a designat ed t arget , t he Android syst em must find t he best component (or components) to handle the intent Android does so by comparing t he cont ent s of t he Int ent obj ect t o int ent f ilt ers, st ruct ures associat ed wit h component s t hat can pot ent ially receive int ent s. Filt ers advert ise t he capabilit ies of a component and delimit t he int ent s it can handle. They open t he component t o t he possibilit y of receiving implicit int ent s of t he advert ised t ype. If a component does not have any int ent filt ers, it can receive only explicit int ent s. A component wit h filt ers can receive bot h explicit and implicit intents.
4.4.2.4.
Intent Filter
Obj ect of t he Int ent Filt er (android.content.IntentFilter) class. In Manifest declared by <int ent filter> tag. Used t o inform t he syst em which implicit int ent s t hey can handle, act ivit ies, services, and broadcast receivers can have one or more intent filters. Intent will be filtered either by Action or Category or Data.
Confidential
Version
The user presses the HOME key, goes to the application launcher, and selects a new application (actually, a new task). The current task goes into the background and the root activity for the new task is displayed. Then, after a short period, the user goes back to the home screen and again selects the previous application (the previous task). That task, with all four activities in the stack, comes forward. When the user presses the BACK key, the screen does not display the activity the user just left (the root activity of the previous task). Rather, the activity on the top of the stack is removed and the previous activity in the same task is displayed. The behavior just described is the default behavior for activities and tasks. But there are ways to modify almost all aspects of it. The association of activities with tasks, and the behavior of an activity within a task, is controlled by the interaction between flags set in the Intent object that started the activity and attributes set in the activity's <activity> element in the manifest. Both requester and respondent have a say in what happens. In this regard, the principal Intent flags are: FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_RESET_TASK_IF_NEEDED FLAG_ACTIVITY_SINGLE_TOP The principal <activity> attributes are: taskAffinity launchMode allowTaskReparenting clearTaskOnLaunch alwaysRetainTaskState finishOnTaskLaunch More Details on Activities and Tasks can be found at http://developer.android.com/intl/de/guide/topics/fundamentals.html#acttask
6.1. Process
The process where a component runs is cont rolled by t he manifest file. The component elements <activity>, <service>,<receiver>, and <provider> each have a process attribute that can specify a process where that component should run. These at t ribut es can be set so t hat each component runs in it s own process, or so t hat some components share a process while others do not. They can also be set so t hat component s of different applicat ions run in t he same process provided t hat t he applicat ions share t he same Linux user ID and are signed by t he same aut horit ies. The <application> element also has a process at t ribut e, for set t ing a default value that applies to all components. All components are instantiated in the main thread of the specified process, and system calls to t he component are dispat ched from t hat t hread. Separat e t hreads are not creat ed for each inst ance. Consequent ly, met hods t hat respond to t hose calls methods
Confidential 10 Version
likeView.onKeyDown() that report user act ions and t he lifecycle not ificat ions always run in t he main thread of the process. This means t hat no component should perform long or blocking operat ions (such as net working operat ions or comput at ion loops) when called by t he syst em, since t his will block any ot her components also in the process. You can spawn separate threads for long operations. Android may decide t o shut down a process at some point , when memory is low and required by other processes that are more immediately serving the user. Application components running in t he process are consequent ly dest royed. A process is rest art ed for t hose component s when there's again work for them to do. When deciding which processes t o t erminat e, Android weighs t heir relat ive import ance t o t he user. For example, it more readily shut s down a process wit h act ivit ies t hat are no longer visible on screen t han a process wit h visible act ivit ies. The decision whet her t o t erminat e a process, therefore, depends on the state of the components running in that process
6.2. Threads
Even t hough you may confine your applicat ion t o a single process, t here will likely be t imes when you will need t o spawn a t hread t o do some background work. Since t he user int erface must always be quick t o respond t o user act ions, t he t hread t hat host s an act ivit y should not also host t ime-consuming operat ions like net work downloads. Anyt hing t hat may not be completed quickly should be assigned to a different thread. Threads are creat ed in code using st andard Java Thread obj ect s. Android provides a number of convenience classes for managing t hreads Looper for running a message loop wit hin a thread, Handler for processing messages, and HandlerThread for set t ing up a t hread wit h a message loop. More details on Process and Threads can be found at: http://developer.android.com/intl/de/guide/topics/fundamentals.html#procthread
Figure 3.
Confidential
Boot up process
11 Version
Linux daemons USB Daemon (usbd) to manage USB connections Android Debug Bridge (adb) to manage ADB connections Debugger Daemon (debuggerd) to manage debug processes Radio Interface Layer Daemon (rild) to manage wireless communication Zygote process A nascent process which initializes a Dalvik VM instance Loads classes and listens for requests to spawn new VM instances Forks on request to create VM instances for managed processes Copy-on-write to maximize re-use and minimize footprint Runtime process Init ializes Service Manager t he cont ext manager t hat handles various service registrations and lookup Registers Service Manager as default context manager for handling services Runtime process sends request for Zygote for start the System Server System Server Runtime process sends request for Zygote to start the System Server Zygote froks a new VM instance for the System Server process and starts the service System Service starts the native system servers e.g. Surface Flinger Audio Flinger These native system servers then register with service manager as IPC service targets. System Service also starts the application framework services e.g. Window manager Telephony service Activity manager Connectivity service These android managed services also register with service manager asIPCservice targets
Figure 4.
Confidential
Boot up Process - 2
12 Version
Aft er syst em server loads all services, t he zygot e creat es t he home applicat ion in a separat e process (also creates a separate instance on Dalvik VM for Home app) Each subsequent application then launched in its own process e.g Contacts, Media Player
Figure 5.
Confidential
13
Version
8.2. Installation
First you will need t o download t he Android SDK pack .zip archive, once downloaded find a suit able installation location on your machine and extract the zipped files. Please not e: This inst allat ion locat ion will be referred t o as $SDK_ROOT from now on t hrough t his tutorial Alt ernat ively you can add / t ools t o your root pat h which will prevent t he need t o specify t he full pat h t o t he t ools direct ory along wit h enabling you t o run Android Debug Bridge (adb) along wit h other command line tools. To add /tools: Linux 1. Edit the ~/.bash_profile or ~/.bashrc files looking for a line that sets the PATH variable. 2. Add the full path location to your $SDK_ROOT/tools location for the PATH variable. 3. If no PATH line exists you can add the line by typing the following: 4. export PATH=${PATH}:<path to your $SDK_ROOT/tools> Mac OS X 1. In t he home direct ory locat e t he .bash_profile and locat ing t he PATH variable add t he location to your $SDK_ROOT/tools folder. Windows XP / Vista 1. Right click on the My Computer icon and select the properties tab. 2. Select the Advanced tab and click the Environment Variables button. 3. In t he new dialog box dowble-click on Pat h (locat ed under Syst em Variables) and t ype in the full path location to the tools directory. The Android SDK also requires a suit able development environment t o work in, here s t he installation guides for each of the supported environments.
13. Restart Eclipse. 14. Aft er rest art , updat e your Eclipse preferences t o point t o t he SDK root direct ory ($SDK_ROOT): Select Window > Preferences... to open t he Preferences panel. (Mac OS X: Eclipse> Preferences) 15. Select Android from the left panel. 16. For the SDK Location in the main panel, press Browse... and find the SDK root directory. 17. Press Apply, then OK
2. Run act ivit yCreat or. In t he command, you must specify a fully-qualified class name as an argument . If you are creat ing a proj ect for new code, t he class represent s t he name of a st ub class t hat t he script will creat e. If you are creat ing a proj ect from exist ing code, you must specify t he name of one Act ivit y class in t he package. Command opt ions for t he script include: --out <folder> which set s t he out put direct ory. By default , t he out put direct ory is t he current directory. If you created a new directory for your project files, use this option to point to it. --ide int ellij , which generat es Int elliJ IDEA proj ect files in t he newly creat ed proj ect Here's an example: /android_linux_sdk/tools$ ./activityCreator.py --out myproject your.package.name.ActivityName package: your.package.name out_dir: myproject activity_name: ActivityName ~/android_linux_sdk/tools$ The act ivit yCreat or script generat es t he following files and direct ories (but will not overwrit e existing ones): AndroidManifest .xml The applicat ion manifest file, synced t o t he specified Act ivit y class for the project. build.xml An Ant file that you can use to build/package the application. src/your/package/name/ActivityName.java The Activity class you specified on input. your_act ivit y.iml, your_act ivit y.ipr, your_act ivit y.iws [only wit h t he -ide int elliJ flag] intelliJ project files. res/ A directory to hold resources. src/ The source directory. bin/ The output directory for the build script. Once complet e you will now be able t o move your folder wherever you choose for development but you ll need t o bear in mind t hen you will need t o use t he adb program in the tools folder in order to send the files to the emulator.
1. Start the emulator (run $SDK_HOME/tools/emulator from the command line) 2. On t he emulat or, navigat e t o t he home screen (it is best not t o have t hat applicat ion running when you reinst all it on t he emulat or; press t he Home key t o navigat e away from that application). 3. Run adb inst all myproj ect / bin/ <appname>.apk t o upload t he execut able. So, for example, t o inst all t he Lunar Lander sample, navigat e in t he command line t o $SDK_ROOT/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk 4. In t he emulat or, open t he list of available applicat ions, and scroll down t o select and st art your application. Please Note: When inst alling an act ivit y for t he first t ime you may need t o rest art t he emulat or engine in order for t he act ivit y t o show up in t he applicat ion launcher or before any ot her applicat ion can call. This is usually down t o t he fact t hat t he package manager normally only examines manifests completely on emulator start-up.
logcat - Dumps a log of syst em messages. The messages include a st ack t race when t he emulat or t hrows an error, as well as Log messages. To run logcat , see t he linked t opic. ... I/ MemoryDealer( 763): MemoryDealer (t his=0x54bda0): Creat ing 2621440 byt es heap at 0x438db000 I/ Logger( 1858): get View() request ing it em number 0 I/ Logger( 1858): get View() request ing it em number 1 I/ Logger( 1858): get View() request ing it em number 2 D/ Act ivit yManager( 763): St opping: Hist oryRecord{409dbb20 com.google.android.home.AllApps} ... Android Log- A logging class t o print out messages t o a log file on t he emulat or. You can read messages in real t ime if you run logcat on DDMS (covered next ). Add a few logging method calls to your code. To use t he Log class, you j ust call Log.v() (verbose), Log.d() (debug), Log.i() (informat ion), Log.w() (warning) or Log.e (error) depending on t he import ance you wish t o assign t he log message. Log.i("MyAct ivit y", "MyClass.get View() Request ing it em number " + posit ion) You can use logcat t o read these messages Traceview - Android can save a log of met hod calls and t imes t o a logging file t hat you can view in a graphical reader called Traceview. See the linked topic for more information. Eclipse plugin - The Eclipse Android plugin incorporat es a number of t hese t ools (ADB, DDMS, logcat output, and other functionality). See the linked topic for more information. Debug and Test Device Set t ings - Android exposes several set t ings t hat expose useful informat ion such as CPU usage and frame rate.
shows t he CPU t ime spent in composit ing t he screen. Not e: You cannot t urn t his feat ure off once it is on, without restarting the emulator. Show screen FPS Displays t he current frame rat e. Most ly useful for games t o see t he overall frame rat e t hey are achieving. Not e: You cannot t urn t his feat ure off once it is on wit hout restarting the emulator. Show background Displays a background pat t ern when no act ivit y screens are visible. This typically does not happen, but can happen during debugging. More Details on the Android SDK will be found at http://developer.android.com/sdk/index.html
Confidential
20
Version
The onStart() and onStop() met hods can be called mult iple t imes, as t he act ivit y alt ernat es between being visible and hidden to the user. The foreground lifetime of an act ivit y happens bet ween a call t o onResume() unt il a corresponding call t o onPause(). During t his t ime, t he act ivit y is in front of all ot her act ivit ies on screen and is int eract ing wit h t he user. An act ivit y can frequent ly t ransit ion bet ween t he resumed and paused st at es for example, onPause() is called when t he device goes t o sleep or when a new act ivit y is st art ed, onResume() is called when an act ivit y result or a new int ent is delivered. Therefore, the code in these two methods should be fairly lightweight
http://developer.android.com/guide/topics/fundamentals.html#lcycles
Confidential
23
Version