
Android Study Guide
Quiz by James Edwards
Tag the questions with any skills you have. Your dashboard will track each student's mastery of each skill.
Brief Summary: Apps should only request location permissions that are critical to user-facing features and properly disclose this to users. The majority of use cases only require location when the user is actively engaging with the app.
Use Case: A weather app that shows current weather conditions based on user location but doesn't need to track location when the app is closed.
Question: According to Android best practices, when should apps typically request location access?
Brief Summary: If your app requires background location access, it must be critical to the app's core functionality, offer clear benefits to users, and be implemented in an obvious way to users.
Use Case: A fitness tracking app that needs to monitor running routes even when the screen is off or user switches to music apps during workout.
Question: What type of app feature commonly requires background location access?
Brief Summary: Google Play Store has updated its policy concerning device location, restricting background location access to apps that need it for core functionality and meet related policy requirements.
Use Case: A social media app wants to add background location tracking to show nearby friends, but this isn't essential to the app's main purpose of sharing photos.
Question: True or False: Following Android's background location best practices guarantees Google Play Store approval for background location usage.
Brief Summary: For apps targeting Android 10 (API level 29) or higher, developers must check for the ACCESS_BACKGROUND_LOCATION permission in addition to ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions.
Use Case: A navigation app targeting Android 10+ needs to continue providing turn-by-turn directions even when the user switches to other apps during driving.
Question: For apps targeting Android 10 or higher, you must check for the _______ permission in addition to ACCESS_FINE_LOCATION and _______ permissions.
Brief Summary: Background location access can occur through various constructs including background services, WorkManager tasks, JobScheduler operations, AlarmManager, and pending intents from app widgets.
Use Case: A delivery tracking app uses WorkManager to periodically update the driver's location to customers even when the driver is using other apps.
Question: Which of the following constructs can potentially access location in the background?
Brief Summary: If your app uses an SDK or library that accesses location, this location access is attributed to your app. Developers should consult library documentation to determine if location access is needed.
Use Case: A gaming app integrates an advertising SDK that secretly tracks user location for targeted ads without the main app developer's knowledge.
Question: True or False: Location access by third-party SDKs or libraries is attributed to your app.
Brief Summary: When evaluating background location access, developers should first determine if it's critical to core functionality. If not needed, it should be removed entirely from the app.
Use Case: A photo editing app realizes it doesn't actually need background location access and should remove the permission to improve user trust.
Question: What should you do if background location isn't critical to your app?
Brief Summary: Developers should make sure users are aware that the app is accessing location in the background, especially for cases that aren't obvious to users.
Use Case: A parental control app tracks child's location but needs to clearly communicate this functionality to both parents and children.
Question: Make sure users are _______ that your app is accessing location in the background, especially for cases that aren't _______ to users.
Brief Summary: Android preserves device battery life by setting background location limits on devices running Android 8.0 (API level 26) and higher, allowing apps to receive location updates only a few times each hour when running in background.
Use Case: A pet tracking app needs to understand the limitations when tracking a lost pet's collar location while running in the background.
Question: On Android 8.0+ devices, how frequently can background apps receive location updates?
Brief Summary: If possible, developers should refactor their location access logic so that location is only requested when the app's activity is visible to users, rather than in the background.
Use Case: A restaurant finder app could refactor to only get location when users open the app to search for nearby restaurants, instead of continuously tracking in background.
Question: True or False: It's recommended to refactor location logic to only request location when the app's activity is visible to users.
Brief Summary: The background location access checklist helps developers identify potential location access in their apps by checking manifest permissions and looking for location API usage in various constructs.
Use Case: A developer auditing their ride-sharing app needs to systematically check all places where location might be accessed in the background.
Question: Use the background location access _______ to identify potential location access _______ in the background.
Brief Summary: For apps targeting Android 10 (API level 29) or higher, removing the ACCESS_BACKGROUND_LOCATION permission from the manifest means all-the-time location access isn't an option.
Use Case: A developer wants to simplify their app's location permissions and eliminate background location access for Android 10+ devices.
Question: What API level introduced the ACCESS_BACKGROUND_LOCATION permission requirement?
Brief Summary: Background location limits were introduced in Android 8.0 (API level 26) to preserve device battery life, restricting how often background apps can receive location updates.
Use Case: A logistics company's fleet tracking app needs to understand when background location limitations started affecting their app's functionality.
Question: Which Android version first introduced background location limits to preserve battery life?
Brief Summary: Apps should evaluate whether background location access is critical to core functionality, and if not needed in the background, it should be removed entirely.
Use Case: A shopping app realizes background location tracking for store notifications isn't essential to its core e-commerce functionality.
Question: True or False: Apps should remove background location access if it's not critical to core functionality.
Brief Summary: Background location access should offer clear benefits to users and be implemented in a way that's obvious to them, ensuring transparency about location tracking.
Use Case: A family safety app needs to clearly explain to users why it tracks location in the background and what benefits this provides.
Question: Background location access should offer clear _______ to users and be done in a way that's _______ to them.
Summary: Track selection is the process that determines which tracks are chosen for playback when a media item contains multiple tracks. This process is configured by TrackSelectionParameters, which allows various constraints and overrides to influence track selection.
Use Case: A streaming video app needs to automatically select the appropriate video quality and audio language when a user plays content that has multiple bitrate options and audio tracks in different languages.
Question: What class is used to configure the track selection process in ExoPlayer?
Summary: The Player.Listener.onTracksChanged callback is triggered when tracks become available (after media preparation), when transitioning between media items, or when selected tracks change.
Use Case: A music player app wants to update its UI to show available audio quality options when a new song starts playing.
Question: When is the onTracksChanged callback triggered?
Summary: Tracks are organized into Groups where tracks within a single Group present the same content but in different formats. Audio tracks with different languages are not grouped together.
Use Case: A sports streaming app provides a main camera feed in 5 different bitrates and an alternative camera angle in 2 bitrates.
Question: Audio tracks in different languages are grouped together.
Summary: A track is considered supported if the Player is able to decode and render its samples, while a track is selected if it has been chosen for playback given the current TrackSelectionParameters.
Use Case: A video player needs to determine which video tracks can be played on the current device and which one is currently being used for playback.
Question: A track is _______ if the Player is able to decode and render its samples.
Summary: ExoPlayer uses sensible defaults for track selection constraints, such as restricting video resolution to display size and preferring audio language matching the user's system Locale setting.
Use Case: A tablet video app automatically selects video resolution that matches the tablet's screen size to avoid unnecessary bandwidth usage.
Question: What does ExoPlayer restrict video resolution to by default?
Summary: Constraint-based track selection allows specifying constraints before knowing what tracks a media item provides, and constraints apply to all media items in a playlist even when items have different available tracks.
Use Case: A playlist contains movies in different languages, and you want to set a preferred audio language that applies to all movies regardless of their specific track forma
Question: Can constraints be specified before media preparation completes?
Summary: To select specific tracks, you first query the player's currently available tracks using Player.getCurrentTracks, then set them on TrackSelectionParameters using a TrackSelectionOverride.
Use Case: A video app allows users to manually select a specific audio track from a dropdown menu showing all available audio options.
Question: What method is used to query currently available tracks?
Summary: Track types like video, audio, or text can be completely disabled using TrackSelectionParameters.Builder.setTrackTypeDisabled method.
Use Case: A podcast app wants to disable video tracks entirely to save bandwidth and only play audio content.
Question: Track types can be disabled using TrackSelectionParameters.Builder._______ method.
Summary: DefaultTrackSelector is a flexible TrackSelector suitable for most use cases and can be provided when building an ExoPlayer instance.
Use Case: A standard video streaming app needs a reliable track selector that handles most common track selection scenarios without custom implementation.
Question: Which TrackSelector implementation is recommended for most use cases?
Summary: When multiple tracks within one track group are selected, the player uses these tracks for adaptive playback, such as multiple video tracks with different bitrates, but only one track plays at any given time.
Use Case: A streaming service provides the same video content in 480p, 720p, and 1080p, and the player switches between them based on network conditions.
Question: When multiple tracks in a group are selected, ExoPlayer uses them for _______ playback.
Summary: TrackSelectionOverride only applies to media items that contain a TrackGroup exactly matching the one specified in the override, so it may not apply to subsequent media items with different tracks.
Use Case: A user manually selects a specific German audio track for one movie, but the next movie in the playlist has different German audio track options.
Question: Does a TrackSelectionOverride apply to all media items in a playlist?
Summary: Track selection parameters can be modified both before and during playback using Player.setTrackSelectionParameters method.
Use Case: A user wants to change the maximum video quality from HD to SD while watching a video to save data.
Question: When can track selection parameters be modified?
Summary: Available constraints include maximum and minimum video properties (width, height, frame rate, bitrate), maximum audio properties (channel count, bitrate), and preferred MIME types and languages.
Use Case: A mobile app wants to limit video to SD quality and prefer English audio tracks while setting a maximum bitrate to conserve data.
Question: Which of the following is NOT a valid track selection constraint?
Summary: An empty TrackSelectionOverride can be specified for a TrackGroup to prevent selection of tracks from that specific group.
Use Case: A parental control app wants to disable a specific subtitle track group that contains inappropriate language while keeping other subtitle options available.
Question: How can you prevent selection from a specific TrackGroup?
Summary: Tunneling may help with efficient video playback of high-resolution streams on TV devices and can be enabled using DefaultTrackSelector.ParametersBuilder.setTunnelingEnabled(true).
Use Case: A smart TV app playing 4K content wants to optimize video playback performance by enabling hardware tunneling.
Question: Tunneling helps with efficient playback of _______ streams on TV devices.
Summary: Audio offload may help save power, particularly for longer playbacks with the screen turned off, and is configured using AudioOffloadPreferences in TrackSelectionParameters.
Use Case: A music streaming app wants to optimize battery usage when users listen to long playlists with the screen off.
Question: Audio offload helps save power during longer playbacks.
Summary: The player needs to prepare a media item to know what tracks it contains, which is why available tracks become known only after preparation completes.
Use Case: A video app shows a loading spinner while determining what quality options and subtitle languages are available for a newly selected movie.
Question: When do available tracks become known?
Summary: ExoPlayer can be built with a custom TrackSelector instance, which can later be obtained using ExoPlayer.getTrackSelector() method.
Use Case: A specialized video app needs custom track selection logic and wants to provide its own TrackSelector implementation during ExoPlayer initialization.
Question: Custom TrackSelector instances can be provided when _______ an ExoPlayer.
Summary: DefaultTrackSelector provides advanced customization options through DefaultTrackSelector.ParametersBuilder, such as allowing mixed MIME type adaptiveness for video.
Use Case: A video streaming app wants to enable adaptive playback between different video codecs (like H.264 and H.265) for the same content.
Question: What provides advanced customization options for DefaultTrackSelector?
Summary: The Tracks object contains a list of Tracks.Group objects, and each Group can be queried for track support, selection status, and Format information.
Use Case: A video player UI needs to display which audio tracks are available, which ones are supported on the device, and which one is currently selected.
Question: The Tracks object contains a list of _______ objects.
Summary: An autofill service is an app that makes it easier for users to fill out forms by injecting data into the views of other apps. The autofill framework is available in Android 8.0 (API level 26) and higher.
Use Case: A password manager app like LastPass that automatically fills login credentials when users encounter login forms in other applications.
Question: What is the minimum Android API level required for the autofill framework?
Summary: Apps that provide autofill services must include a service declaration in the app manifest with specific attributes including android:name pointing to the AutofillService subclass and android:permission declaring BIND_AUTOFILL_SERVICE.
Use Case: A banking app that wants to provide autofill services for credit card information needs to properly declare the service in its AndroidManifest.xml file.
Question: What permission must be declared for autofill services?
Summary: An app can verify whether it's the currently enabled autofill service by calling the hasEnabledAutofillServices() method of the AutofillManager class.
Use Case: A password manager wants to check if it's currently set as the active autofill service before prompting the user to enable autofill functionality.
Question: Apps can check if they are the current autofill service using hasEnabledAutofillServices().
Summary: The autofill service receives requests to fill out client views through the onFillRequest() method, which receives an AssistStructure object containing information about the views to be filled.
Use Case: When a user focuses on a username field in a login form, the autofill service's onFillRequest() method is called with details about the form structure.
Question: The autofill service receives fill requests through the _______ method.
Summary: Autofill services package user data in Dataset objects and send them in a FillResponse object by calling the onSuccess() method of FillCallback.
Use Case: A password manager has found matching credentials for a login form and needs to package the username and password data to send back to the system.
Question: What object is used to package user data for autofill responses?
Summary: If the autofill service doesn't have data to satisfy the request, it should pass null to the onSuccess() method. If there's an error processing the request, it should call onFailure() instead.
Use Case: An autofill service searches its database but finds no stored credentials for the current login form, so it needs to indicate no data is available.
Question: What should be passed to onSuccess() when no autofill data is available?
Summary: Autofill services can provide multiple datasets that satisfy a request, and the Android system will show multiple options in the autofill UI, one for each dataset.
Use Case: A password manager has stored three different accounts for the same website and wants to show all three options to the user in the autofill dropdown.
Question: Can autofill services provide multiple datasets in a single response?
Summary: The service can navigate ViewNode objects in the AssistStructure to retrieve autofill data, using methods like getAutofillId() to get the information needed to fulfill the request.
Use Case: An autofill service needs to examine the structure of a registration form to identify which fields correspond to username, password, and email address.
Question: ViewNode objects are contained within the _______ object.
Summary: Using the autofillHints attribute is the first approach that services must use to describe view contents, but if client apps don't provide this attribute, services must use their own heuristics.
Use Case: A form field doesn't have autofillHints specified, so the autofill service must analyze the field's getText() or getHint() methods to determine if it's a password field.
Question: What is the primary way for services to identify view contents?
Summary: To save user data, the autofill service must indicate interest by including a SaveInfo object in the FillResponse, specifying the data type and minimum views that need to change to trigger a save request.
Use Case: A user manually fills out a new account registration form, and the autofill service wants to save this information for future use.
Question: Services indicate interest in saving data using _______ objects.
Summary: The onSaveRequest() method is called when the service needs to persist user data, usually after the client activity finishes or when the client app calls commit().
Use Case: A user completes filling out a shipping address form, and the autofill service needs to store this new address information in its database.
Question: When is the onSaveRequest() method typically called?
Summary: Autofill services must encrypt sensitive data before persisting it, but non-sensitive labels (like "work" or "personal" account markers) should not be encrypted so they can be used in presentations.
Use Case: A password manager stores account credentials but keeps account labels like "Work Gmail" unencrypted so they can be displayed in the autofill UI before user authentication.
Question: Should autofill services encrypt sensitive data before storing it?
Summary: Starting with Android 10, autofill services can postpone the autofill save UI using the SaveInfo.FLAG_DELAY_SAVE flag for multi-screen workflows.
Use Case: A banking app registration process uses one screen for username entry and another for password entry, and the save UI should only appear after both screens are completed.
Question: The FLAG_DELAY_SAVE feature is available starting from Android __.
Summary: Autofill services can require user authentication before filling views by presenting boilerplate data and specifying an Intent for authentication, useful for scenarios requiring primary passwords or biometric verification.
Use Case: A password manager requires fingerprint authentication before revealing stored credit card details to fill a payment form.
Question: What can services use to require authentication before autofill?
Summary: After successful authentication, the activity must call setResult() with RESULT_OK and set the EXTRA_AUTHENTICATION_RESULT extra to the FillResponse object containing the populated dataset.
Use Case: After a user successfully provides their master password, the authentication activity needs to return the decrypted login credentials to the autofill service.
Question: Authentication activities return results using EXTRA_AUTHENTICATION_RESULT.
Summary: Autofill services must organize data in logical groups called partitions that isolate concepts from different domains, such as credentials, addresses, and payment information.
Use Case: A comprehensive autofill service separates stored data so that login credentials are never mixed with credit card information in the same dataset.
Question: What are logical groups of autofill data called?
Summary: Organizing data in partitions allows services to expose the minimum amount of relevant information required to satisfy a request and better protect user data.
Use Case: When filling a login form, the service only exposes username and password data from the credentials partition, not the user's stored address or payment information.
Question: Data partitioning helps expose the _______ amount of relevant information.
Summary: Services can identify the field that originated the request by calling the isFocused() method while traversing the AssistStructure object.
Use Case: An autofill service needs to determine which specific field the user tapped to trigger the autofill request in a form with multiple input fields.
Question: How can services identify the field that triggered the autofill request?
Summary: Autofill services can assist with SMS one-time codes using the SMS Retriever API, available on Android 9 (API level 28) and higher, requiring user consent and that the target app isn't already using SMS Retriever.
Use Case: A banking app's autofill service can automatically fill SMS-based two-factor authentication codes when users receive them during login processes.
Question: SMS one-time code autofill requires Android API level __ or higher.
Summary: Chrome allows third-party autofill services to natively autofill forms, and developers can query Chrome settings and deep link to Chrome settings where users can enable third-party autofill services.
Use Case: A password manager app wants to check if Chrome is configured to use third-party autofill services and guide users to enable this setting if it's not active.
Question: Can third-party autofill services work natively with Chrome?
Summary: Chrome uses Android's ContentProvider to communicate autofill settings information, and apps can query this using ContentResolver with specific URIs and column names.
Use Case: A password manager needs to programmatically check Chrome's third-party autofill mode status before prompting users to configure Chrome integration.
Question: Chrome communicates autofill settings through Android's _______.
Summary: Advanced autofill scenarios include integration with keyboards (Android 11+), dataset pagination for large responses, and compatibility mode for apps that don't explicitly implement autofill APIs.
Use Case: A comprehensive autofill service wants to display suggestions directly in the keyboard interface rather than using dropdown menus for a more seamless user experience.
Question: Keyboard integration for autofill is available starting from which Android version?
Summary: To prevent exceeding Binder transaction size limits, autofill services should keep FillResponse objects small by adding no more than 20 Dataset objects at a time.
Use Case: A password manager has 50 stored accounts for a website and needs to implement pagination to avoid system exceptions when sending the response.
Question: What is the recommended maximum number of Dataset objects per FillResponse?
Summary: For apps that split user data across multiple screens, autofill services must use client state bundles and the FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE flag to handle save operations correctly.
Use Case: A social media registration flow uses separate screens for username entry and password creation, requiring the autofill service to wait for both steps before saving.
Question: Multi-screen data saving uses client state _______ to track partial data.
Summary: Autofill services can customize the save UI to provide additional information about what is saved, either through simple text or customized views, and can modify the cancel button appearance.
Use Case: A password manager wants to show users exactly which fields will be saved (username, password, and website URL) in a custom dialog before storing the information.
Question: Can autofill services customize the appearance of the save UI?
Summary: CameraX provides configuration options for image capture through ImageCapture.OutputFileOptions.
Use Case:When you need to customize where and how captured images are saved.
Question: Which of these is NOT a valid configuration option in ImageCapture.OutputFileOptions?
Summary: CameraX allows setting quality options for JPEG images.
Use Case: When you want to balance image quality and file size.
Question: What method sets JPEG quality?
Summary: CameraX can automatically rotate captured images based on device orientation.
Use Case: When you want portrait/landscape photos to display correctly without manual rotation.
Question: CameraX automatically corrects image orientation during capture.
Summary: Metadata can be attached to captured images.
Use Case: When you need to store location or timestamp with photos.
Question: The ______ class is used to attach metadata to captured images.
Summary: CameraX provides different ways to handle captured images.
Use Case: When deciding between immediate processing or saving to file.
Question: Which is NOT a valid capture mode?
Summary: You can customize flash modes for capture.
Use Case: When needing flash for low-light conditions.
Question: What sets the flash mode?
Summary: CameraX supports setting a target rotation for output images.
Use Case: When you want consistent orientation across all captures.
Question: Target rotation affects image capture orientation.
Summary: Callbacks notify about image capture events.
Use Case: When you need to show UI feedback during capture.
Question: The ______ interface handles image save events.
Summary: CameraX provides control over capture timing.
Use Case: When you need to synchronize captures with other events.
Question: What can you use to delay capture?
Summary: You can crop captured images automatically.
Use Case: When you need square aspect ratio photos.
Question: What sets the crop aspect ratio?
Summary: A one-to-one relationship between two entities means each instance of the parent entity corresponds to exactly one instance of the child entity, and vice versa.
Use Case: A music streaming app where each user has only one library, and each library corresponds to exactly one user.
Question: What type of relationship exists when each parent entity instance corresponds to exactly one child entity instance?
Summary: To define a one-to-one relationship, one entity must include a variable that is a reference to the primary key of the other entity.
Use Case: A Library entity that contains a userOwnerId field referencing the primary key of the User entity.
Question: In one-to-one relationships, what must one entity reference from the other entity?
Summary: Both entities in a one-to-one relationship must be annotated with @Entity to define them as database tables.
Use Case: Defining User and Library classes as Room entities using the @Entity annotation.
Question: Both entities in a one-to-one relationship must use the @Entity annotation.
Summary: The @PrimaryKey annotation is used to designate the primary key field in each entity class.
Use Case: Defining userId as the primary key in the User entity and libraryId as the primary key in the Library entity.
Question: The _______ annotation is used to designate the primary key field in entity classes.
Summary: To query one-to-one relationships, you create a new data class that holds instances of both the parent and child entities.
Use Case: Creating a UserAndLibrary data class that contains both a User instance and a Library instance.
Question: What do you create to model the one-to-one relationship for querying?
Summary: The @Embedded annotation is used to include the parent entity instance within the relationship data class.
Use Case: Using @Embedded val user: User in the UserAndLibrary class to embed the User entity.
Question: Which annotation embeds the parent entity in the relationship class?
Summary: The @Relation annotation defines the relationship between parent and child entities by specifying which columns link them together.
Use Case: Using @Relation with parentColumn = "userId" and entityColumn = "userOwnerId" to link User and Library entities.
Question: The @Relation annotation defines relationships between parent and child entities.
Summary: The parentColumn parameter in @Relation specifies the name of the primary key column of the parent entity.
Use Case: Setting parentColumn = "userId" when the User entity's primary key is userId.
Question: The _______ parameter specifies the parent entity's primary key column name.
Summary: The entityColumn parameter in @Relation specifies the name of the column in the child entity that references the parent entity's primary key.
Use Case: Setting entityColumn = "userOwnerId" when the Library entity has a userOwnerId field that references the User's primary key.
Question: What does the entityColumn parameter specify in @Relation?
Summary: The @Transaction annotation must be added to DAO methods that query one-to-one relationships because Room needs to run multiple queries.
Use Case: Adding @Transaction to the getUsersAndLibraries() method to ensure atomic execution of multiple queries.
Question: Why is @Transaction required for one-to-one relationship queries?
Summary: The DAO method for querying one-to-one relationships typically uses a SELECT query on the parent entity table.
Use Case: Using @Query("SELECT * FROM User") to retrieve all users and their associated libraries.
Question: One-to-one relationship queries typically SELECT from which entity's table?
Summary: Room automatically handles the execution of multiple queries when retrieving one-to-one relationships, requiring the @Transaction annotation for atomicity.
Use Case: Room first queries the User table, then queries the Library table based on the userOwnerId foreign key relationships.
Question: Room automatically handles multiple queries for one-to-one relationships.
Summary: The method that retrieves one-to-one relationship data returns a List of the relationship data class containing both entities.
Use Case: getUsersAndLibraries() returns List<UserAndLibrary> where each item contains a User and its associated Library.
Question: One-to-one relationship methods return a _______ of the relationship data class.
Summary: In the example, the Library entity contains userOwnerId as a foreign key reference to establish the relationship with User.
Use Case: Library entity has userOwnerId field that matches the userId primary key in the User entity.
Question: What establishes the link between entities in one-to-one relationships?
Summary: The relationship data class combines both entities using @Embedded for the parent and @Relation for the child entity.
Use Case: UserAndLibrary class uses @Embedded for User and @Relation for Library to model their relationship.
Question: Relationship data classes use @Embedded and _______ annotations.
Summary: Each instance of the relationship data class holds one instance of the parent entity and the corresponding instance of the child entity.
Use Case: Each UserAndLibrary instance contains exactly one User object and exactly one Library object.
Question: Each relationship data class instance holds how many parent and child entity instances?
Summary: The @Transaction annotation ensures that the entire operation of querying related entities runs atomically, preventing data inconsistency.
Use Case: If the app crashes during the query, @Transaction ensures either all data is retrieved or none, preventing partial results.
Question: @Transaction ensures atomic execution of relationship queries.
Summary: Room requires two queries to retrieve one-to-one relationships: one for the parent entity and one for the child entity based on the foreign key relationship.
Use Case: First query retrieves all User records, second query retrieves Library records where userOwnerId matches each userId.
Question: How many queries does Room run for one-to-one relationships?
Summary: The foreign key field in the child entity must match the data type of the primary key in the parent entity.
Use Case: If userId is of type Long in User entity, then userOwnerId in Library entity must also be of type Long.
Question: Foreign key and primary key must have _______ data types.
Summary: One-to-one relationships are useful when you need to split related data across multiple tables while maintaining a strict one-to-one correspondence.
Use Case: Separating user profile information into User and UserProfile entities where each user has exactly one profile.
Question: What correspondence do one-to-one relationships maintain between entities?
Summary: WorkManager automatically calls Worker.doWork() on a background thread from an Executor specified in WorkManager's Configuration.
Use Case: A photo processing app that uses Worker to resize images in the background without blocking the UI thread.
Question: On which thread does WorkManager automatically call Worker.doWork()?
Summary: By default, WorkManager sets up an Executor for background work, but you can customize your own Executor for specific needs.
Use Case: An app that needs all background work to execute sequentially might create a single-threaded Executor.
Question: Can you customize the Executor used by WorkManager?
Summary: To customize the Executor, you must initialize WorkManager manually rather than using the default initialization.
Use Case: A media app that wants to share an existing background Executor with WorkManager to optimize resource usage.
Question: How must you initialize WorkManager to customize the Executor?
Summary: WorkManager allows you to specify a custom Executor during manual configuration using Configuration.Builder().setExecutor().
Use Case: Setting up a fixed thread pool of 8 threads for handling multiple concurrent background tasks efficiently.
Question: The _______ method is used to specify a custom Executor in WorkManager configuration.
Summary: Worker.doWork() is a synchronous call where you must do all background work in a blocking fashion before the method exits.
Use Case: A file download worker that must complete the entire download process synchronously before returning a result.
Question: What type of call is Worker.doWork()?
Summary: If you call an asynchronous API in doWork() and return a Result immediately, your callback may not operate properly.
Use Case: Making a network request with a callback inside doWork() and returning Result.success() before the callback completes.
Question: Asynchronous APIs work properly when called directly in doWork().
Summary: If you need to use asynchronous APIs, you should consider using ListenableWorker instead of Worker.
Use Case: An app that needs to use Retrofit with async callbacks should use ListenableWorker for proper async handling.
Question: What should you use instead of Worker for asynchronous operations?
Summary: When a running Worker is stopped for any reason, it receives a call to Worker.onStopped().
Use Case: A large file processing worker that needs to clean up temporary files when the work is cancelled by the system.
Question: Which method is called when a Worker is stopped?
Summary: You can override onStopped() or call Worker.isStopped() to checkpoint your code and free up resources when necessary.
Use Case: A data synchronization worker that checks isStopped() periodically to gracefully halt processing when cancelled.
Question: What method can you call to check if a Worker has been stopped?
Summary: Workers should check isStopped() periodically during long-running operations to optimize behavior when stopped.
Use Case: A worker downloading 100 files should check isStopped() between downloads to avoid unnecessary work after cancellation.
Question: Long-running Workers should check isStopped() periodically for optimization.
Summary: Once a Worker has been stopped, the Result returned from Worker.doWork() will be ignored by the system.
Use Case: A stopped image processing worker that returns Result.success() - this result won't be processed by WorkManager.
Question: What happens to Results returned from stopped Workers?
Summary: Workers should return ListenableWorker.Result.success() when work completes successfully and Result.failure() when an error occurs.
Use Case: A backup worker returns Result.success() after successful backup or Result.failure() if network errors occur.
Question: Which Result should be returned when work completes successfully?
Summary: The background thread for Worker execution comes from the Executor specified in WorkManager's Configuration.
Use Case: An app configures WorkManager with a custom ThreadPoolExecutor to control thread creation and management.
Question: Where does the background thread for Worker execution come from?
Summary: You can create different types of Executors such as fixed thread pools, single-threaded executors, or custom executors based on your needs.
Use Case: A social media app uses a single-threaded executor to ensure posts are uploaded in the correct chronological order.
Question: Can you create single-threaded Executors for sequential work execution?
Summary: Worker constructor takes Context and WorkerParameters as required parameters for initialization.
Use Case: A notification worker that needs Context to access NotificationManager and WorkerParameters to get input data.
Question: What parameters does the Worker constructor require?
Summary: You must override the doWork() method in your Worker subclass to implement the actual background work logic.
Use Case: Creating a CustomWorker class that extends Worker and implements doWork() to perform specific business logic.
Question: Which method must you override in Worker subclasses?
Summary: Workers are expected to finish all background work in a blocking fashion by the time the doWork() method exits.
Use Case: A database cleanup worker that must complete all deletion operations before returning from doWork().
Question: How should background work be completed in doWork()?
Summary: WorkManager provides automatic thread management but allows customization for specific threading requirements.
Use Case: A gaming app that needs precise control over background thread priorities for asset loading.
Question: WorkManager provides automatic thread management with customization options.
Summary: When configuring a custom Executor, you use Configuration.Builder() to build the WorkManager configuration.
Use Case: An enterprise app that uses Configuration.Builder() to set up WorkManager with a custom thread pool for security compliance.
Question: What class is used to build custom WorkManager configuration?
Summary: The example shows how to properly handle stopping in Workers by checking isStopped() in loops to break out early.
Use Case: A batch processing worker that checks isStopped() in each iteration to avoid processing remaining items after cancellation.
Question: Where should you check isStopped() in long-running operations?
Summary: Starting in Android 13 (API level 33), users can stop apps running foreground services from the notification drawer using the Task Manager workflow.
Use Case: A music streaming app running a foreground service can be stopped by users directly from the notification drawer's Task Manager interface.
Question: In which Android version can users stop apps with foreground services from the notification drawer?
Summary: The Task Manager functionality works regardless of the app's target SDK version, meaning all apps with foreground services are affected.
Use Case: An older app targeting API level 28 can still be stopped by users through Task Manager when running on Android 13+ devices.
Question: Does Task Manager functionality depend on the app's target SDK version?
Summary: The Task Manager shows a list of apps currently running foreground services, labeled as "Active apps" with a Stop button next to each app.
Use Case: A fitness tracking app appears in the "Active apps" list with a Stop button when it's running a foreground service for GPS tracking.
Question: What is the Task Manager's list of foreground service apps called?
Summary: When users press the Stop button in Task Manager, the system removes the entire app from memory, not just the foreground service.
Use Case: A navigation app with a foreground service gets completely removed from memory when stopped, including all background activities and cached data.
Question: What happens to the app when the Stop button is pressed in Task Manager?
Summary: The system removes the app's activity back stack when stopped through Task Manager, clearing all activities in the task.
Use Case: A messaging app with multiple open chat screens loses its entire activity stack when stopped through Task Manager.
Question: What happens to the app's activities when stopped through Task Manager?
Summary: Any ongoing media playback stops immediately when the app is stopped through Task Manager.
Use Case: A podcast app playing audio through a foreground service stops playback entirely when the user stops it via Task Manager.
Question: Media playback continues after stopping through Task Manager.
Summary: The notification associated with the foreground service is removed when the app is stopped through Task Manager.
Use Case: A download manager's persistent notification disappears from the status bar when the app is stopped through Task Manager.
Question: What happens to the foreground service notification when stopped?
Summary: Although the app is removed from memory, it remains in the device's app history for user access.
Use Case: A stopped weather app can still be found in the recent apps screen and can be relaunched from there.
Question: The app remains in _______ after being stopped through Task Manager.
Summary: Scheduled jobs continue to execute at their scheduled time even after the app is stopped through Task Manager.
Use Case: A backup app stopped through Task Manager will still run its scheduled daily backup job using JobScheduler.
Question: Do scheduled jobs execute after the app is stopped through Task Manager?
Summary: Alarms continue to trigger at their scheduled time or time window after the app is stopped through Task Manager.
Use Case: An alarm clock app stopped through Task Manager will still trigger morning alarms set by the user.
Question: Alarms are cancelled when apps are stopped through Task Manager.
Summary: You can test the app stopping behavior using the ADB command "adb shell cmd activity stop-app PACKAGE_NAME" in a terminal window.
Use Case: Testing how a meditation app handles being stopped by running "adb shell cmd activity stop-app com.example.meditation" during development.
Question: What ADB command tests app stopping behavior?
Summary: The Task Manager workflow is accessible from the notification drawer where users can see and manage active foreground services.
Use Case: Users can swipe down the notification shade and access Task Manager to see all apps currently running foreground services.
Question: Where is the Task Manager workflow accessible from?
Summary: The entire app stops when using Task Manager, which is more comprehensive than just stopping the foreground service alone.
Use Case: A file transfer app loses all its background processing, cached connections, and UI state when stopped through Task Manager.
Question: What scope of the app is affected when stopped through Task Manager?
Summary: Task Manager provides users with direct control over apps running foreground services, enhancing user agency over device resources.
Use Case: A user notices their device slowing down and uses Task Manager to stop a resource-intensive photo processing app running a foreground service.
Question: Task Manager enhances user control over device resources.
Summary: The Stop button appears next to each app in the Active apps list, providing individual control over each foreground service.
Use Case: A user can selectively stop a battery-intensive GPS tracking app while keeping a music player foreground service running.
Question: What appears next to each app in the Active apps list?
Summary: The Task Manager feature affects all foreground services regardless of their type or importance to ensure consistent user control.
Use Case: Both critical system utilities and entertainment apps with foreground services can be stopped through the same Task Manager interface.
Question: The Task Manager affects _______ foreground services regardless of type.
Summary: Testing the stopping behavior helps developers ensure their apps handle unexpected termination gracefully and maintain data integrity.
Use Case: A note-taking app should save unsaved changes and maintain sync state even when stopped abruptly through Task Manager.
Question: Why should developers test the app stopping behavior?
Summary: The workflow from notification drawer to Task Manager represents a streamlined user experience for managing active background services.
Use Case: Users can quickly identify and stop battery-draining apps without navigating through complex settings menus.
Question: The Task Manager workflow provides a streamlined user experience.
Summary: Apps should be designed to handle sudden termination gracefully since users now have direct control over stopping foreground services.
Use Case: A cloud storage app should implement proper state saving and recovery mechanisms to handle Task Manager stops without data loss.
Question: How should apps be designed regarding Task Manager stopping?
Summary: The system's comprehensive stopping approach ensures complete resource cleanup when users choose to stop apps through Task Manager.
Use Case: A video editing app with heavy memory usage gets completely cleaned up when stopped, freeing all resources for other apps.
Question: What type of resource cleanup occurs when apps are stopped through Task Manager?
Summary: Starting with Android 8.0 (API level 26), MediaPlayer includes APIs that support the playback of DRM-protected material.
Use Case: A streaming video app that needs to play premium content protected by DRM using MediaPlayer APIs.
Question: Which Android version introduced DRM support in MediaPlayer?
Summary: MediaPlayer DRM APIs operate at a higher level than MediaDrm and don't expose the underlying extractor, DRM, and crypto objects.
Use Case: A developer chooses MediaPlayer DRM APIs for simpler implementation instead of working directly with MediaDrm's low-level components.
Question: MediaPlayer DRM APIs operate at a higher level than MediaDrm.
Summary: The current MediaPlayer DRM implementation can handle Widevine-protected local media files and Widevine-protected remote or streaming media files.
Use Case: A movie rental app that plays both downloaded Widevine-protected files and streams Widevine-protected content from servers.
Question: What DRM scheme is supported by MediaPlayer for both local and remote content?
Summary: To manage DRM-controlled media, you need to include new DRM methods alongside the usual flow of MediaPlayer calls.
Use Case: An existing video player app needs to add DRM support while maintaining its current MediaPlayer workflow.
Question: DRM methods are used _______ the usual MediaPlayer flow.
Summary: The DRM workflow includes setting data source, optional DRM configuration, prepare, checking DrmInfo, and DRM preparation steps.
Use Case: A subscription-based music app implementing the complete DRM workflow from initialization to playback.
Question: Which method is used to check if the source has DRM content?
Summary: setOnDrmConfigHelper() is an optional step that allows custom configuration of DRM properties before opening the DRM session.
Use Case: A corporate video app that needs to set specific DRM properties for enterprise security requirements.
Question: Is setOnDrmConfigHelper() required for DRM playback?
Summary: prepareDrm() prepares the DRM configuration for the current source and may provision the device if not already done.
Use Case: A streaming platform preparing DRM for a newly downloaded movie on a device that hasn't been provisioned yet.
Question: What method prepares DRM configuration for the current source?
Summary: getKeyRequest() returns an opaque key request byte array that must be sent to a license server for DRM key retrieval.
Use Case: A video streaming service obtaining a key request to send to their license server for content decryption keys.
Question: The _______ method returns a key request byte array for the license server.
Summary: provideKeyResponse() informs the DRM engine about the key response received from the license server.
Use Case: A streaming app providing the license server response back to the DRM engine to enable content decryption.
Question: Which method provides the license server response to the DRM engine?
Summary: For offline key requests, provideKeyResponse() returns a key-set identifier that can be used with restoreKeys() to restore keys to a new session.
Use Case: A download-to-watch-later app storing key-set identifiers to restore offline content keys when the user wants to watch.
Question: Offline key requests return a key-set identifier from provideKeyResponse().
Summary: prepareDrm() runs synchronously by default, but the first DRM preparation may require provisioning which can take time due to network operations.
Use Case: A streaming app experiencing delays during first-time DRM setup due to device provisioning requirements.
Question: What can cause prepareDrm() to take variable time on new devices?
Summary: You can avoid blocking on prepareDrm() by defining and setting a MediaPlayer.OnDrmPreparedListener for asynchronous preparation.
Use Case: A video player app using OnDrmPreparedListener to avoid blocking the UI thread during DRM preparation.
Question: The _______ listener enables asynchronous DRM preparation.
Summary: MediaPlayer.OnDrmInfoListener works with OnDrmPreparedListener and prepareAsync() to initialize DRM asynchronously.
Use Case: A live streaming app using both listeners with prepareAsync() to handle DRM setup without blocking the main thread.
Question: Which listener combination enables fully asynchronous DRM setup?
Summary: OnDrmInfoListener receives a callback when the data source content is protected, allowing DRM setup before the onPrepared() callback.
Use Case: A video app receiving onDrmInfo() callback to set up DRM protection before the media is ready for playback.
Question: onDrmInfo() callback executes before onPrepared() callback.
Summary: Starting with Android 8.0, MediaPlayer can decrypt Common Encryption Scheme (CENC) and HLS sample-level encrypted media for H.264 and AAC streams.
Use Case: A streaming service playing HLS content with sample-level encryption (METHOD=SAMPLE-AES) for H.264 video and AAC audio.
Question: What encryption scheme does MediaPlayer support for H.264 and AAC?
Summary: MediaPlayer previously supported full-segment encrypted media (METHOD=AES-128) before adding sample-level encryption support.
Use Case: A legacy streaming app that used METHOD=AES-128 encryption continues to work with newer MediaPlayer versions.
Question: The _______ encryption method was previously supported for full-segment encryption.
Summary: releaseDrm() should be called after stopping the MediaPlayer to properly clean up DRM resources.
Use Case: A video player app calling releaseDrm() in its cleanup code to free DRM-related resources when done playing.
Question: When should releaseDrm() be called in the MediaPlayer lifecycle?
Summary: The OnDrmConfigHelper callback is called synchronously in the thread that called prepareDrm(), allowing DRM property access.
Use Case: A custom media player setting specific DRM properties using getDrmPropertyString() and setDrmPropertyString() in the config helper.
Question: OnDrmConfigHelper callback executes synchronously during prepareDrm().
Summary: MediaPlayer DRM APIs don't provide the full functionality of MediaDrm but support the most common use cases.
Use Case: A standard streaming app choosing MediaPlayer DRM APIs over MediaDrm for simpler implementation of common DRM scenarios.
Question: Do MediaPlayer DRM APIs provide full MediaDrm functionality?
Summary: The DRM workflow requires examining available UUIDs from DrmInfo and choosing one before calling prepareDrm().
Use Case: A multi-platform streaming app checking available DRM schemes from DrmInfo and selecting the appropriate UUID for content protection.
Question: What must be examined and chosen from DrmInfo before calling prepareDrm()?