Android Study Guide
Lesson 1 The Android Ecosystem
1.1 Introducing Android
1.1.1 Complete, Open, Free
- Complete — Android is a complete platform with a secure Linux operating system at its base and a robust Java-based software framework which allows for the development of powerful mobile applications.
- Open — The Android platform is open source. Device manufacturers can create custom Android implementations for their devices, and app developers have unprecedented access to device features in their applications.
- Free — Neither developers nor device manufacturers pay royalties or licensing fees to develop for the platform.
1.1.2 What Android Is
- A free open-source operating system for embedded devices (i.e., an object that contains a special-purpose computing system like cellphones, point-of-sale terminals, ATMs, household appliances, etc.).
- An open source development platform for creating applications.
- Devices which run the Android operating system and applications created for it.
Android is made up of several necessary and dependent parts, including:
- A Compatibility Definition Document (CDD) and Compatibility Test Suite (CTS) — which describe the capabilities required for a device to support the software stack.
- A Linux operating system kernel— which 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—For devices running Android version 5.0 (API level 21) or higher, each app runs in its own process and with its own instance of the Android Runtime (ART). Previous versions of Android utilized the Dalvik VM (DVM).
- An application framework— which agnostically exposes system services to the application layer, including the window manager and location manager, databases, telephony, and sensors.
- A user interface framework— which is used to host and launch applications.
- A set of core pre-installed applications— Android devices ship with certain "core" apps including an email client, SMS management application, PIM (personal Information Management) app (e.g, claendar, contact list, etc.), a Webkit-based web browser, a music player and picture gallery, camera, etc.
- A software development kit (SDK)—used by developers to create applications, including the related tools, plug-ins, and documentation.
1.1.3 What Android Isn't
- A Java ME implementation — Android applications are written in Java, but they are not run with the Java Mobile Edition Virtual Machine (VM). Android has its own custom VM.
- Simply an application layer (e.g., Nokia's UIQ or S60) — Android includes an application layer, but it also encompasses the underlying operating system, API libraries, and the applications themselves.
- A mobile phone handset— Android includes a reference design for device manufacturers, with some devices running close to "pure" implementations of the Android operating system (e.g., Nexus and Pixel). But Android is designed to support many different hardware devices.
- Google's Answer to the iPhone— iPhone is a fully proprietary hardware and software platform. iPhone apps run only on Apple's iPhone and custom implementations of iPhone software are not supported. Android, on the other hand, is an open-source software stack produced and supported by the open handset alliance (OHA) and designed to operate on many devices.
1.1.4 Android Open Source Project
The Android Open Source Project (AOSP) is an initiative led by Google that makes the source code of the Android Operating System available to read, review, and modify.
1.1.5 Android Open Handset Alliance
The Open Handset Alliance (OHA) is a business alliance which includes many of the largest device manufacturers, chip makers, software developers and service providers. Membership in the OHA allows companies license (and include on Android devices) Google Mobile Services (GMS) which includes proprietary Google mobile apps like Google Play, YouTube, Google Maps, and Gmail.
1.2 Android Software Stack / Platform
Android is a Java-based platform. Android-compatible devices feature a Linux-based operating system stack for managing devices, memory, and processes. Android's Java Libraries cover telephony, video, speech graphics, connectivity, UI programming among other device features (an interactive table of the Android architecture can be found here).
1.2.1 The Linux Kernel
The foundation of the Android platform is the Linux Kernel. For example, the Android Runtime (ART) relies on the Linux kernel for underlying functionalities such as threading and low-level memory management.
Using a Linux kernel allows Android to take advantage of key security features and allows device manufacturers to develop hardware drivers for a well-known kernel.
1.2.2 Hardware Abstraction Layer
The Hardware Abstraction Layer (HAL) provides standard interfaces that expose device hardware capabilities to the higher-level Java API framework. The HAL consists of multiple library modules, each of which implements an interface for a specific type of hardware component, such as the camera or bluetooth module. When a framework API makes a call to access device hardware, the Android system loads the library module for that hardware component.
1.2.3 Android Runtime
For devices running Android version 5.0 (API level 21) or higher, each app runs in its own process and with its own instance of the Android Runtime (ART). ART is written to run multiple virtual machines on low-memory devices by executing DEX files, a bytecode format designed specially for Android that's optimized for minimal memory footprint. Build toolchains, such as Jack, compile Java sources into DEX Bytecode, which can run on the Android platform.
Some of the major features of ART include the following:
- Ahead-of-time (AOT) and just-in-time (JIT) compilation
- Optimized garbage collection (GC)
- Better debugging support, including a dedicated sampling profiler, detailed diagnostic exceptions and crash reporting, and the ability to set watchpoints to monitor specific fields
- Prior to Android version 5.0 (API level 21), Dalvik was the Android runtime. If your app runs well on ART, then it should work on Dalvik as well, but the reverse may not be true.
Android also includes a set of core runtime libraries that provide most of the functionality of the Java programming language, including some Java 8 language features, that the Java API framework uses.
ART is an improvement over DVM due to the use of AOT or Ahead-of-time Compilation vs DVMs just-in-time or JIT approach. AOT allows apps to be compiled on installation rather than every time the app is launched which improves app performance and saves battery life. (note: both AOT and JIT are used as of in Android 7.0 to achieve the "best of both worlds" with regard to app speed, system performance and use of storage space).
More Info: ART and Dalvik
1.2.4 Native C/C++ Libraries
Many core Android system components and services, such as ART and HAL, are built from native code that require native libraries written in C and C++. The Android platform provides Java framework APIs to expose the functionality of some of these native libraries to apps. For example, you can access OpenGL ES through the Android framework’s Java OpenGL API to add support for drawing and manipulating 2D and 3D graphics in your app. Additional Native Libraries include: SQLite for databases, the Media Framework, Webkit, and the libc C library
If you are developing an app that requires C or C++ code, you can use the Android NDK to access some of these native platform libraries directly from your native code.
1.2.5 Java API Framework
The entire feature-set of the Android OS is available to you through APIs written in the Java language. These APIs form the building blocks you need to create Android apps by simplifying the reuse of core, modular system components and services, which include the following:
- A rich and extensible View System you can use to build an app’s UI, including lists, grids, text boxes, buttons, and even an embeddable web browser
- A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
- A Notification Manager that enables all apps to display custom alerts in the status bar
- An Activity Manager that manages the lifecycle of apps and provides a common navigation back stack
- Content Providers that enable apps to access data from other apps, such as the Contacts app, or to share their own data
1.2.6 System Apps or Application Layer
Android comes with a set of core apps for email, SMS messaging, calendars, internet browsing, contacts, and more. Apps included with the platform have no special status among the apps the user chooses to install. So a third-party app can become the user's default web browser, SMS messenger, or even the default keyboard (some exceptions apply, such as the system's Settings app).
The system apps function both as apps for users and to provide key capabilities that developers can access from their own app. For example, if your app would like to deliver an SMS message, you don't need to build that functionality yourself—you can instead invoke whichever SMS app is already installed to deliver a message to the recipient you specify.
1.3 Android Development
Android is application-neutral—third-party developers can access device features just like the applications which come pre-installed on the device.
The Android SDK or Software Development Kit provides the tools, including an extensive set of APIs which allow developers to create Android Applications.
Where so many devices run different versions of Android software, it's important for Android Developers to know the features and functionality offered in various Android Versions and API Levels.
Platform Version | API Level | VERSION_CODE | Key User Features Added | Key Developer Features Added | Release Date | Notes |
---|---|---|---|---|---|---|
Android 7.1.1 Android 7.1 |
25 | N_MR1 |
|
|
October 4, 2016 | Platform Highlights |
Android 7.0 | 24 | N |
|
|
August 22, 2016 | Platform Highlights |
Android 6.0 | 23 | M |
|
December 7, 2015 | Platform Highlights | |
Android 5.1 | 22 | LOLLIPOP_MR1 |
|
April 21, 2015 | Platform Highlights | |
Android 5.0 | 21 | LOLLIPOP |
|
|
October 17, 2014 | |
Android 4.4W | 20 | KITKAT_WATCH |
KitKat for Wearables Only | |||
Android 4.4 | 19 | KITKAT |
|
|
October 31, 2013 | Platform Highlights |
Android 4.3 | 18 | JELLY_BEAN_MR2 |
|
|
July 24, 2013 | Platform Highlights |
Android 4.2, 4.2.2 | 17 | JELLY_BEAN_MR1 |
Platform Highlights | |||
Android 4.1, 4.1.1 | 16 | JELLY_BEAN |
Platform Highlights | |||
Android 4.0.3, 4.0.4 | 15 | ICE_CREAM_SANDWICH_MR1 |
Platform Highlights | |||
Android 4.0, 4.0.1, 4.0.2 | 14 | ICE_CREAM_SANDWICH |
||||
Android 3.2 | 13 | HONEYCOMB_MR2 |
||||
Android 3.1.x | 12 | HONEYCOMB_MR1 |
Platform Highlights | |||
Android 3.0.x | 11 | HONEYCOMB |
Platform Highlights | |||
Android 2.3.4 Android 2.3.3 |
10 | GINGERBREAD_MR1 |
Platform Highlights | |||
Android 2.3.2 Android 2.3.1 Android 2.3 |
9 | GINGERBREAD |
||||
Android 2.2.x | 8 | FROYO |
Platform Highlights | |||
Android 2.1.x | 7 | ECLAIR_MR1 |
Platform Highlights | |||
Android 2.0.1 | 6 | ECLAIR_0_1 |
||||
Android 2.0 | 5 | ECLAIR |
||||
Android 1.6 | 4 | DONUT |
Platform Highlights | |||
Android 1.5 | 3 | CUPCAKE |
Platform Highlights | |||
Android 1.1 | 2 | BASE_1_1 |
||||
Android 1.0 | 1 | BASE |
1.3.1 Android Platform Versions and Android APIs
The Android Platform Version (e.g., Android 7.1 Nougat, Android 6 Marshmallow, etc.) refers to a particular version of the Android operatng system (think: the OS as it exists on Android devices—devices are said to run particular versions of Android). Each Andoid Version is given a dessert-themed nickname.
The Android Platform provides a Framework API that applications can use to interact with the underlying Android system. The Framework API includes:
- A core set of packages and classes
- A set of XML elements and attributes for declaring a manifest file
- A set of XML elements and attributes for declaring and accessing resources
- A set of Intents
- A set of permissions that applications can request, as well as permission enforcements included in the system
The API Level is always a single integer and you cannot derive the API Level from its associated Android version number (for example, it is not the same as the major version or the sum of the major and minor versions)
Updates to the framework API are designed so that the new API remains compatible with earlier versions of the API.
Each Android Platform Version supports exactly one API Level.
For information about the relative numbers of devices that are running each version, see the Platform Versions Dashboards Page.
1.3.2 Android SDK
The Android SDK includes several tools and utilities to help you create, test, and debug your projects. The SDK download comes with the base tools and additional packages are downloaded via the SDK Manager. In order to start developing applications, you must install the Platform-tools and at least one version of the Android platform.
1.3.3 Development Tools
- The Android Virtual Device and SDK Managers – Used to create and manage AVDs and to download SDK packages, respectively. The AVD hosts an Emulator running a particular build of Android, letting you specify the supported SDK version, screen resolution, amount of SD card storage available, and available hardware capabilities (such as touchscreens and GPS). See : Android Studio Docs: Create And Manage Virtual Devices.
- The Android Emulator – An implementation of the Android VM designed to run within an AVD on your development computer. Use the Emulator to test and debug your Android applications.
- Dalvik Debug Monitoring Service (DDMS) – Use the DDMS to monitor and control the Emulators on which you’re debugging your applications.
-
Android Debug Bridge (ADB) – A client-server application that provides a link to virtual and physical devices. It lets you copy files, install compiled application packages (.apk), and run shell commands. You can find the
adb
tool inandroid_sdk/platform-tools/
. See : Android Studio Docs: Android Debug Bridge. - Logcat – A utility used to view and filter the output of the Android logging system.
- Android Asset Packaging Tool (AAPT) – Constructs the distributable Android package files (.apk).
- SQLite3 – A database tool that you can use to access the SQLite database files created and used by Android.
- Traceview and dmtracedump – Graphical analysis tools for viewing the trace logs from your Android application.
- Hprof-conv – A tool that converts HPROF profiling output files into a standard format to view in your preferred profiling tool.
- MkSDCard – Creates an SD card disk image that can be used by the Emulator to simulate an external storage card.
- Dx – Converts Java .class bytecode into Android .dex bytecode.
- Hierarchy Viewer – Provides both a visual representation of a layout’s View hierarchy to debug and optimize your UI, and a magnified display to get your layouts pixel-perfect.
- Draw9patch – A handy utility to simplify the creation of NinePatch graphics using a WYSIWYG editor.
- Monkey and Monkey Runner – Monkey runs within the VM, generating pseudo-random user and system events. Monkey Runner provides an API for writing programs to control the VM from outside your application.
- ProGuard – A tool to shrink and obfuscate your code by replacing class, variable, and method names with semantically meaningless alternatives. This is useful to make your code more difficult to reverse engineer.
1.3.4 Documentation
Android development is assisted by an ever-growing library of documentation. SDK docs are available online and can also be downloaded from the SDK Manager. They will be located in, for example, [Username]/AppData/Local/Android/sdk/docs/index.html
- Android API Guides A List of guides which teach developers how to build apps using Android APIs.
- Android Studio User Guide
1.4 App Fundamentals and App Components
Android apps provide multiple entry points and are built as a combination of distinct components that can be invoked individually. For instance, an individual activity provides a single screen for a user interface, and a service independently performs work in the background.
From one component you can start another component using an intent. You can even start a component in a different app, such as an activity in a maps app to show an address. This model provides multiple entry points for a single app and allows any app to behave as a user's "default" for an action that other apps may invoke.
Android apps consist of four main app components:
- Activities
- Services
- Content Providers
- Broadcast Receivers
1.4.1 Activity
An activity is the entry point for interacting with the user.
- Think of an Activity as a single screen with a user interface.
- Activities can start each other–even across applications (e.g., a camera app can start the activity in the email app that composes new mail to allow the user to share a picture).
An activity facilitates the following key interactions between system and app:
- Keeping track of what the user currently cares about (what is on screen) to ensure that the system keeps running the process that is hosting the activity.
- Knowing that previously used processes contain things the user may return to (stopped activities), and thus more highly prioritize keeping those processes around.
- Helping the app handle having its process is killed so the user can return to activities with their previous state restored.
- Providing a way for apps to implement user flows between each other, and for the system to coordinate these flows. (The most classic example here being share.)
You implement an activity as a subclass of the Activity
class. For more information about Activity in the Activities developer guide.
1.4.2 Service
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
- Used for long-running operations (e.g., database work, accessing the internet, or reading a file).
- A Service does not provide a user interface.
- Another application component can start a service, and it continues to run in the background even if the user switches to another application.
A service is implemented as a subclass of Activity
. For more information about the Service class, see the Services developer guide.
1.4.3 BroadcastReceiver
A Broadcast Receiver listens for Broadcast Intents and allows the app to respond to system-wide broadcast announcements.
- The system can deliver broadcasts even to apps that aren't currently running.
- Broadcasts can originate from the system (e.g., screen turned off, battery low, picture captured), or from individual apps.
A broadcast receiver is implemented as a subclass of BroadcastReceiver
and each broadcast is delivered as an Intent
object. For more information, see the BroadcastReceiver
class.
1.4.4 ContentProvider
A content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that your app can access.
- Other apps can query or modify the data if the content provider allows it.
- The data the Content Provider provides is identified by a URI scheme.
- Content providers can read and write data that is private to your app and not shared. For example, the Note Pad sample app uses a content provider to save notes.
A content provider is implemented as a subclass of ContentProvider
and must implement a standard set of APIs that enable other apps to perform transactions. For more information, see the Content Providers developer guide.
1.5 Interview Questions
1. What is Android?
Android is a free open-source mobile operating system developed by Google for embedded devices. Android devices operate on a Linux kernel operating system. Utilizing the Android Software Development Kit (SDK)developers can leverage Android's robust Java-based software framework to create Android applications.
2. Describe the benefits of Android being open source.
The open source nature of Android allows the Android operating system to run on a wide variety of devices – not just devices produced by a single manufacturer. Device manufacturers may implement custom versions of Android to specifically suit their customer's needs. For developers, Android offers a free and robust platform for developing applications.
3. List six components of the Android Platform Architecture
1) The Linux Kernel, 2) The Hardware Abstraction Layer, 3) The Native C/C++ Libraries, 4) The Android Runtime, 5) The Java API Framework 6) The System Apps or Application Layer
4. List six components of Android's Core C/C++ Libraries
1) Graphics Libraries (e.g.,SGL and OpenGL), 2) Webkit, 3) libc (The C Runtime Library), 4) The Surface Manager, 5) SQLite 6) Media Library.
5. List six components Android's Application Framework – include four Manager components and two non-Manager components.
1) Content Providers 2) View System 3) Activity Manager 4) Package Manager 5) Resource Manager 6) Location Manager.
6. List the core components of Android Applications.
1) Activities 2) Services 3) Broadcast Receivers 4) Content Providers.
6. What is the AAPT?
The Android Asset Packaging Tool is a part of the SDK which allows us the view, create, and update zip-compatible archives (e.g., .zip, .jar, .apk). It is the base builder for Android applications.
7. What is an AVD?
An AVD is an Android Virtual Device. AVDs are used to simulate the hardware and software configurations of different Android devices, allowing you test your applications on a variety of hardware platforms. The Android Emulator runs AVDs.
8. What is an APK?
APK stands for Android Application Package. An .apk file is the file format used for installing software (e.g., apps) on the Android operating system. It is a compressed package containing the whole project.
9. What is the Android Context?
In Android, Context is an abstract class whose implementation is provided by the Android system. It gives the context of the current state of the application or of a particular Object (e.g., a particular Activity Context).
10. What is an Android App?
An Android App is a software application running on the Android platform. Apps are collections of different Activities, Services, Receivers, and Listeners. Each Android App has a single manifest (manifest.xml file), and is compiled into a single .apk file.
11. What is NDK?
NDK stands for Native Development Kit, and is a toolset that lets developers write code for Android apps in native-code languages such as C and C++.
12. What is ANR, when does it happen, and how should it be avoided?
ANR stands for Applications Not Responding and occurs when the Main Thread of the application is blocked for a period of time: 5 seconds in an Activity, 10 seconds in a BroadcastReceiver, 20 seconds in a Service. To avoid it, time-consuming operations (e.g., file read/write, network access, database access) should be performed in a background thread.
13. The Android framework makes use of several programming languages. What are two of them and where are they used?
The Android application framework layers and applications are written in Java. Lower-level drivers and the library layer of the framework are written in C and C++.
14. What is the Android API Level and how does it differ from the Android Version Number?
The Android Platform Version (e.g., Android 7.1 Nougat, Android 6 Marshmallow, etc.) refers to a particular version of the Android operatng system. Each Andoid Version is given a dessert-themed nickname. The Android Platform provides a Framework API that applications can use to interact with the underlying Android system. The API Level is an integer number representing the level of this Android Framework API. Each Android Platform Version supports exactly one API Level and the API Level shows the programmer what functionalities may be included when designing an app.
15. What is the difference between an App's versionCode and its versionName?
An App's versionCode is an number used to identify an app's release version (e.g., 1.0, 1.2, 2.0, etc.). An app's versionName is a string or number representating the app version to the user.
16. On what type of devices may Android be run?
The Android operating system may be run on almost all types of electronic devices provided they support Android hardware configurations. This may include mobile phones, watches, cars, tablets, laptops, TVs, headphones, etc.
17. What does the acronym AOSP stand for?
Android Open Source Project
18. True or false: Joining the Open handset Alliance allows device makers to bundle Google Mobile Services.
True
19. What is ART? How is ART different from DVM?
ART stands for Android Run Time. It allows for running apps in multiple virtual machines (VMs) on mobile devices by executing .dex bytecode files—a low-memory-footprint file format specifically designed for Android. In Android Platfrom Version 5.0, ART Replaced DVM (Dalvik Virtual Machine). ART is an improvement over DVM due to: 1) The use of AOT or Ahead-of-time Compilation vs DVMs just-in-time or JIT approach. AOT allows apps to be compiled on installation rather than every time the app is launched which improves app performance and saves battery life. (note: both AOT and JIT are used as of in Android 7.0 to achieve the "best of both worlds" with regard to app speed, system performance and use of storage space). 2) Improved Garbage Collection (GC). 3) Development and Debugging Improvements.
20. How many manifests may an application have?
One. Libraries and modules included as part of an application have their own application manifest files as well.
21. Why is the package name of an application important?
It serves as a unique identifier for the application.
22. What are the components of an application that are defined in the manifest?
Activities, Services, Broadcast Receivers, Content Providers.
23. Why do certain permissions need to be defined in the app's manifest?
By default, no application is allowed to perform any operations that could adversely impact other applications, the operating system, or the user — e.g., reading or writing the user's private data, reading or writing another application's private files, performing network access, keeping the device awake, etc. Permissions allow access to the protected parts of the API and allows an application to interact with other applications.
24. What are some permissions that may be required in the manifest file?
INTERNET, READ_LOGS, CALL_EMERGENCY_NUMBERS, SET_WALLPAPER, DEVICE_POWER.
25. What can be contained within the <application> tag of the app manifest?
Information (in the form of .xml tags) about activities, services, receivers, and providers used in the app.
26. What are the two required elements in the manifest declararation?
The <manifest> element and <application> element. They may occur only once.
27. What is an Activity?
An Activity is an application component which is visualized in a separate screen. Most applications contain several activities.
28. Explain the "last in, first out" stack mechanism in the context of activities?
In an application, each activity can start another activity. When a new Activity is started, the old Activity is stopped, but preserved by the system so when the user presses the back button, the LAST that was visible is the FIRST to appear visible again.
29. What is the difference between startActivity() and startActivityForResult()?
With startActivityForResult(), we expect something to be returned from the started Activity. In the first Activity, we implement the onActivityResult() callback method.
30. In which phase of the Activity Lifecycle should the global state be declared (as the Layout, for example)?
In the onCreate() callback. Here is where the essential components of the Activity are initailized. Within the setContentView() method, we define the layout.
31. What are the phases of the Activity Lifecycle?
onCreate()
onStart()
onRestart()
onResume()
onPause()
onStop()
onDestroy()
32. Between which calls does the entire cycle of the Activity happen?
Between onCreate() where resources are created, and onDestroy() where resources are released.
33. Between which calls can the user see and interact with the Activity?
Between onStart() - the visible phase after the Activity has been created and onStop() - when the activity is stopped?
34. How can a destroyed Activity's state be saved?
In onSavedInstanceState() which uses a Bundle as an argument where activity about the state of the Activity can be saved.
35. If not specified, what happens if the device configurations are changed at runtime?
The Activity is destroyed (onDestroy() is called) and re-created (onCreate() is called).
The configChanges attribute can be set in the app manifest, to prevent this, although a better option is to save the data needed to recreate state.
36. Which method is called to shut down an Activity?
There are two: finish() - to finish the Activity itself, and finishActivity() - to allow others to kill the Activity. Note: finish() is equivalent to hitting the back button.
37. What is seamlessness and how is it applicable in Android?
Seamlessness is the non-interrupted flow of the application. It is up to the developer to handle all possible hindrances for the user e.g., low battery, configuration changes, permissions, etc.
38. What is the Android splash screen?
A screen that appears briefly before the main screen. It is used to show progress, a company logo, etc.
39. What are Fragments?
A Fragment represents a behavior or a portion of the user interface in an Activity. Fragments have their own layouts and can be added or removed at runtime. Fragments have their own lifecycle which is dependent upon that of the Activity in which they are contained. Fragments are modular and can be re-used in different Activities.
40. What is the difference between a DialogFragment, a ListFragment, and a PreferenceFragment?
PreferenceFragment displays a heirarchy of Preference objects as a list.
ListFragment displays a list of items which are managed by an Adapter.
DialogFragment displays a floating Dialog to the user.
41. What is the Interface for interacting with Fragments inside an Activity?
The FragmentManager
42. What is a Fragment Transaction?
The ability to add, remove, replace and perform other actions with Fragments upon user interaction are Fragment transactions. In order to perform a fragment transaction, you use the APIs in FragmentTransaction.
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.commit();
43. Can the parent Activity be accessed from a Fragment?
Yes, by using getActivity().
44. What are the states in which a Fragment can exist?
Resumed, Paused, and Stopped.
45. What is the difference between a Fragment and an Activity in terms of their lifecycles?
The way they are stored in the backstack - by default, the Activity is added at the top of the backstack in order to be available when the user presses the back button.
If we want the same behavior by the Fragment, we need to explicitly call addToBackStack() on the FragmentTransaction.
46. Is there a correlation between the Activity and Fragment Lifecycles?
Yes, each lifecycle callback for the Activity results in a similar callback for the Fragment.
47. In comparison to an Activity, are there additional lifecycle callbacks for the Fragment?
Yes, they are:
onAttach()
onCreateView()
onActivityCreated()
onDestroyView()
onDetach()
48. What is a Service?
A component of the application that lets you handle long-running operations in the background. It doesn't have a user interface. It is not a thread and it doesn't run on a separate thread.
49. What are the basic forms a Service takes?
Started (e.g., via startService() within an Activity). A Service may continue running even if the component it is started from is destroyed.
Bound - allows application components to bind to it. It is dependent on the component bound to it.
50. How long does a bound service run for?
As long as there is a component bound to it.
51. Where should a Service be declared in order to be used?
In the manifest in a <service> element, a child of the <application> element.
52. What is the difference between stopSelf() and stopService() in a Service's context?
stopSelf() is called by the Service itself when the job it was created for is done. stopService() is called by another component in order for the Service to be stopped.
53. Does a Service run in a thread separate from that of the UI thread?
No. It runs in the main thread of the application by default.
54. When a Service is created, why is it better to extend IntentService rather than Service?
IntentService creates a default worker thread that executes all intents, whereas, in a Service, you create a new thread in which to perform work.