Unit 6 - Practice Quiz

CSE227 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary Android View component used to display web pages directly inside an application?

Building and Managing Web Apps in WebView Easy
A. TextView
B. BrowserView
C. InternetView
D. WebView

2 Which method is called to load a specific URL into a WebView?

Building and Managing Web Apps in WebView Easy
A. webView.openUrl("https://example.com")
B. webView.displayPage("https://example.com")
C. webView.setUrl("https://example.com")
D. webView.loadUrl("https://example.com")

3 What permission must be added to the AndroidManifest.xml file for a WebView to access the internet?

Building and Managing Web Apps in WebView Easy
A. android.permission.INTERNET
B. android.permission.WEB_ACCESS
C. android.permission.WIFI
D. android.permission.ACCESS_NETWORK_STATE

4 By default, what happens when a user clicks a link inside a WebView?

Building and Managing Web Apps in WebView Easy
A. The link opens in the same WebView.
B. Nothing happens.
C. The application crashes.
D. The default web browser app opens to handle the link.

5 How do you enable JavaScript execution within a WebView?

Advance android programming Easy
A. JavaScript is enabled by default.
B. By calling webView.enableJavaScript();
C. By adding <uses-permission android:name="android.permission.JAVASCRIPT" /> to the manifest.
D. By calling webView.getSettings().setJavaScriptEnabled(true);

6 Which HTML meta tag is essential for creating responsive web pages that adapt to different screen sizes within a WebView?

Supporting Different Screens in web Apps Easy
A. <meta name="author" ... >
B. <meta name="viewport" ... >
C. <meta name="description" ... >
D. <meta name="keywords" ... >

7 What does width=device-width in the viewport meta tag signify?

Supporting Different Screens in web Apps Easy
A. It makes all images on the page responsive.
B. It sets the width of the page to the device's height.
C. It sets the page width to a fixed value of 320px.
D. It sets the width of the page to follow the screen-width of the device.

8 In CSS, which type of unit is recommended for font sizes to ensure they scale properly across different screen densities in a WebView?

Supporting Different Screens in web Apps Easy
A. Absolute units like pt (points)
B. Relative units like em or rem
C. Absolute units like in (inches)
D. Absolute units like px (pixels)

9 What is a major advantage of using a WebView to display certain content instead of building a fully native UI?

Migrating to WebView in Android Easy
A. Content can be updated on a web server without releasing a new app version.
B. It has direct access to all device hardware by default.
C. It always provides better performance than a native screen.
D. It works perfectly offline without any extra configuration.

10 What is the purpose of the addJavascriptInterface() method in WebView?

Advance android programming Easy
A. To check if JavaScript is enabled.
B. To allow JavaScript code in the WebView to call methods in your Android app's Java/Kotlin code.
C. To inject a new JavaScript library into the web page.
D. To disable certain JavaScript functions for security.

11 Which class should you extend to handle events like page loading finished or URL navigation within your WebView?

Building and Managing Web Apps in WebView Easy
A. WebViewClient
B. PageLoader
C. UrlHandler
D. WebChromeClient

12 A business wants to migrate their 'Terms of Service' page from a native TextView to a WebView. What is the primary benefit of this change?

Migrating to WebView in Android Easy
A. The terms can be updated on a server without an app update.
B. The text will load faster in a WebView.
C. It provides better security for the text content.
D. The app's installation size will be significantly smaller.

13 What is a common CSS technique used to apply different styles for different devices or screen sizes?

Supporting Different Screens in web Apps Easy
A. JavaScript alerts
B. Server-side rendering
C. Media Queries
D. HTML tables

14 What is a potential disadvantage of migrating a complex, interactive screen from native code to a WebView?

Migrating to WebView in Android Easy
A. The app will become larger in size.
B. The app will no longer be able to access the internet.
C. Inability to use HTML or CSS for styling.
D. Potential for slower performance and less smooth user experience.

15 What is the primary role of the WebChromeClient?

Advance android programming Easy
A. To handle UI-related events like progress updates, JavaScript alerts, and favicons.
B. To manage the WebView's cache.
C. To handle URL loading and page navigation.
D. To enable or disable JavaScript.

16 How can you load locally stored HTML content from your app's assets folder into a WebView?

Building and Managing Web Apps in WebView Easy
A. Using the URL http://localhost/assets/your_file.html
B. Using the URL file:///android_asset/your_file.html
C. It is not possible to load local files.
D. Using the URL assets://your_file.html

17 When considering migrating a feature to a WebView, what type of content is generally the best fit?

Migrating to WebView in Android Easy
A. Content that is primarily text and images, like articles or help pages.
B. High-performance 3D games.
C. Core OS interactions like the notification drawer.
D. The app's main navigation bar.

18 If a web page appears too zoomed out in a WebView on a high-density screen, which setting might be missing?

Supporting Different Screens in web Apps Easy
A. The viewport meta tag with initial-scale=1.0
B. The INTERNET permission
C. A WebChromeClient
D. A WebViewClient

19 To navigate back through the history of a WebView, what method should you call?

Advance android programming Easy
A. webView.navigateBack()
B. webView.history.back()
C. webView.previousPage()
D. webView.goBack()

20 Before calling webView.goBack(), which method should you check to see if there is a page to go back to?

Advance android programming Easy
A. webView.canGoBack()
B. webView.hasHistory()
C. webView.isBackPossible()
D. webView.historyExists()

21 An Android application uses a WebView to display a modern web application. By default, the web app's interactive JavaScript components are not working. What is the most likely reason and how do you fix it?

Building and Managing Web Apps in WebView Medium
A. The WebViewClient has not been set, so JavaScript cannot execute.
B. Hardware acceleration is disabled for the activity, preventing complex script execution.
C. The INTERNET permission is missing in AndroidManifest.xml.
D. JavaScript is disabled by default for security reasons. You must enable it using webView.getSettings().setJavaScriptEnabled(true);.

22 You want to prevent a WebView from opening external links in the device's default browser, and instead handle all URL loading within the app itself. Which method should you override?

Building and Managing Web Apps in WebView Medium
A. Override onJsAlert() in a custom WebChromeClient.
B. Override shouldOverrideUrlLoading() in a custom WebViewClient.
C. Override onLoadResource() in a custom WebViewClient.
D. Set webView.getSettings().setBlockNetworkLoads(true);.

23 A web page designed for desktops looks too wide and requires horizontal scrolling when loaded in a WebView on a mobile device. Which HTML meta tag is essential to add to the web page's <head> to make it adapt to the device's screen width?

Supporting Different Screens in web Apps Medium
A. <meta name="HandheldFriendly" content="true">
B. <meta name="mobile-web-app-capable" content="yes">
C. <meta name="viewport" content="width=device-width, initial-scale=1.0">
D. <meta http-equiv="X-UA-Compatible" content="IE=edge">

24 What is the correct and secure way to expose a method from your Android Kotlin/Java code to be callable by JavaScript running inside a WebView?

Advance android programming Medium
A. Annotate the method with @JavascriptInterface in a dedicated class and bind an instance of that class using webView.addJavascriptInterface().
B. Use webView.evaluateJavascript() to poll for changes from the web page.
C. Set a custom WebChromeClient and override onJsPrompt() to handle messages from JavaScript.
D. There is no secure way to do this; it should always be avoided.

25 A developer needs to display a progress bar that updates as a web page loads in a WebView. Which client and method are most appropriate for this task?

Building and Managing Web Apps in WebView Medium
A. WebChromeClient and its onReceivedTitle() method.
B. WebViewClient and its onLoadResource() method.
C. WebChromeClient and its onProgressChanged() method.
D. WebViewClient and its onPageFinished() method.

26 You are migrating a web application that relies heavily on HTML5 localStorage to an Android app using WebView. After loading the app, you notice that data saved in localStorage does not persist between app sessions. Which WebSettings call is required to fix this?

Migrating to WebView in Android Medium
A. webView.getSettings().setDomStorageEnabled(true);
B. webView.getSettings().setAppCacheEnabled(true);
C. webView.getSettings().setDatabaseEnabled(true);
D. webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

27 To ensure a non-mobile-optimized webpage is initially zoomed out to fit the screen's width when loaded in a WebView, which pair of WebSettings methods should be set to true?

Supporting Different Screens in web Apps Medium
A. setBuiltInZoomControls(true) and setDisplayZoomControls(true)
B. setUseWideViewPort(true) and setLoadWithOverviewMode(true)
C. setSupportZoom(true) and setUseWideViewPort(true)
D. setLoadWithOverviewMode(true) and setJavaScriptEnabled(true)

28 How can you programmatically execute a JavaScript function from your native Android code and asynchronously receive its string result?

Advance android programming Medium
A. Using webView.evaluateJavascript("myFunction();", callback).
B. Using webView.postWebMessage().
C. This requires overriding onJsPrompt in WebChromeClient.
D. Using webView.loadUrl("javascript:myFunction();") and a @JavascriptInterface.

29 In your WebView-based app, you want the physical back button to navigate the WebView's history first, and only exit the app if there is no history to go back to. Where should this logic be implemented?

Building and Managing Web Apps in WebView Medium
A. In the onKeyDown() method of the WebView itself.
B. In the shouldOverrideUrlLoading() method of the WebViewClient.
C. In the onBackPressed() method of the host Activity.
D. In the onBackPressed() method of the host Fragment.

30 A migrated web application includes a file upload feature using an <input type="file"> element. This feature does not work in the WebView. What must be implemented to support file selection?

Migrating to WebView in Android Medium
A. The READ_EXTERNAL_STORAGE permission in the AndroidManifest.xml.
B. Enabling DOM storage with setDomStorageEnabled(true).
C. A custom WebViewClient that overrides shouldInterceptRequest().
D. A custom WebChromeClient that overrides the onShowFileChooser() method.

31 To deliver the best quality images for a web app running in a WebView on high-density displays (e.g., XHDPI, XXHDPI), what is the recommended web development practice?

Supporting Different Screens in web Apps Medium
A. Use only SVG (Scalable Vector Graphics) for all images.
B. Use responsive images with the <picture> element or the srcset attribute to provide multiple image resolutions.
C. Set webView.setInitialScale(200) to force images to render larger.
D. Hardcode all image widths and heights in pixels to prevent scaling.

32 A user logs out of your app, and you need to completely clear all data associated with the WebView, including cookies, cache, and local storage. Which of the following approaches is most effective?

Advance android programming Medium
A. Call webView.clearView() to reset the visual state.
B. Simply destroy and recreate the WebView instance.
C. Call webView.clearCache(true), webView.clearHistory(), and CookieManager.getInstance().removeAllCookies(null).
D. Disable JavaScript using webView.getSettings().setJavaScriptEnabled(false).

33 To improve WebView rendering performance, especially for pages with complex CSS animations and transitions, what setting should be enabled for the Activity hosting the WebView in AndroidManifest.xml?

Building and Managing Web Apps in WebView Medium
A. android:hardwareAccelerated="true"
B. android:configChanges="orientation|screenSize"
C. android:largeHeap="true"
D. android:windowSoftInputMode="adjustResize"

34 A web app that works in modern desktop browsers uses cutting-edge JavaScript (ES2020) features. When loaded into a WebView on an older Android device (e.g., API 21), these features cause errors. What is the most likely reason?

Migrating to WebView in Android Medium
A. Hardware acceleration is not supported, which is required for modern JavaScript.
B. JavaScript is disabled on older devices.
C. The INTERNET permission works differently on older Android versions.
D. The WebView on older Android versions is based on an older version of the Chromium engine which does not support modern JavaScript syntax.

35 You are debugging a responsive layout in a WebView. What CSS media query is specifically used to target devices based on their screen's pixel density?

Supporting Different Screens in web Apps Medium
A. @media (-webkit-min-device-pixel-ratio: 2)
B. @media (orientation: landscape)
C. @media (prefers-color-scheme: dark)
D. @media (min-width: 480px)

36 To mitigate the risk of Cross-Site Scripting (XSS) when loading potentially untrusted third-party content in a WebView, which two WebSettings properties should be set to false unless absolutely necessary?

Advance android programming Medium
A. setUseWideViewPort() and setLoadWithOverviewMode()
B. setJavaScriptEnabled() and setAllowFileAccess()
C. setSupportZoom() and setBuiltInZoomControls()
D. setDomStorageEnabled() and setDatabaseEnabled()

37 Your WebView loads a page over HTTPS, but some resources on that page (like images or scripts) are loaded over HTTP. The WebView blocks this mixed content by default on newer Android versions. How can you change this behavior to allow mixed content?

Building and Managing Web Apps in WebView Medium
A. Set webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW).
B. There is no way to allow mixed content; all resources must be served over HTTPS.
C. Override onReceivedSslError in WebViewClient and call handler.proceed().
D. Add android:usesCleartextTraffic="true" to the application tag in the manifest.

38 You need to intercept network requests made by a WebView to modify headers or provide a cached response from your app's native cache. Which WebViewClient method is designed for this purpose?

Advance android programming Medium
A. onPageFinished(WebView view, String url)
B. shouldInterceptRequest(WebView view, WebResourceRequest request)
C. shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
D. onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse)

39 When converting a web app to a WebView-based Android app, you want to replace the standard browser alert() dialogs with native Android AlertDialogs. Which client and method must you implement?

Migrating to WebView in Android Medium
A. WebChromeClient and override onJsPrompt().
B. WebViewClient and override onReceivedError().
C. WebChromeClient and override onJsAlert().
D. WebViewClient and override shouldOverrideUrlLoading().

40 A web app in a WebView uses CSS vh units (viewport height) for layout. When the Android soft keyboard appears, the WebView resizes, causing the layout to break. What windowSoftInputMode setting in AndroidManifest.xml for the Activity can help prevent this resizing behavior?

Supporting Different Screens in web Apps Medium
A. stateVisible
B. adjustPan
C. stateHidden
D. adjustResize

41 You are using WebView.evaluateJavascript() to invoke a JavaScript function that returns a large JSON object. To avoid performance issues on the main thread, you want to process the result on a background thread. Which of the following approaches is the most robust and correct for handling the asynchronous result off the main thread?

Building and Managing Web Apps in WebView Hard
A. Wrap the evaluateJavascript() call within a coroutine using suspendCancellableCoroutine and switch context to Dispatchers.IO before processing the result returned by the callback.
B. Use evaluateJavascript() with a ValueCallback and immediately dispatch the processing of the result to a background thread pool from within the onReceiveValue method.
C. The ValueCallback for evaluateJavascript is always invoked on the main thread. A better approach is to use a @JavascriptInterface where the JavaScript calls a native method, which can then perform the work on a background thread.
D. Configure the WebView to run its JavaScript execution on a background thread using a hidden WebSettings API, so the ValueCallback is also executed on a background thread.

42 When implementing WebViewClient.shouldInterceptRequest(WebView view, WebResourceRequest request), you decide to replace the network call with a response from a local, encrypted database. To avoid blocking the UI thread, you perform the database query and decryption on a background thread. What is the primary challenge with this asynchronous approach and how is it correctly solved?

Advance android programming Hard
A. The method is called on a background thread, so you can perform the I/O operation directly. No special handling is needed.
B. The method must return a WebResourceResponse synchronously. The correct way is to use a CountDownLatch to block the WebView's internal thread until the background operation completes.
C. This method cannot be asynchronous. All processing must be done on the thread it was called on, so you should use LOAD_CACHE_ELSE_NETWORK instead.
D. You cannot perform background operations; the method will time out. The only solution is to pre-cache the decrypted data in memory before the request is made.

43 To ensure your web content respects the display cutout (notch) area on modern Android devices, you need to pass the safe area insets from the native layout to the web app's CSS. What is the most effective technique to achieve this?

Supporting Different Screens in web Apps Hard
A. Use View.setOnApplyWindowInsetsListener on the WebView, get the DisplayCutout insets, and then inject a <style> tag into the HTML <head> using evaluateJavascript() that sets CSS variables like --safe-area-inset-top.
B. Enable a setting like webSettings.setSupportDisplayCutout(true) which automatically handles the insets.
C. The WebView automatically handles display cutouts via the user-agent string, and the web content only needs to use the env(safe-area-inset-top) CSS function.
D. Override onConfigurationChanged, check for inset changes, and reload the entire WebView with a new URL parameter containing the inset values.

44 You are migrating a native login flow, which uses OkHttp with a custom Authenticator for automatic refresh token logic, to a WebView-based flow. How can you replicate the automatic token refresh functionality for network requests originating from the WebView?

Migrating to WebView in Android Hard
A. Use CookieManager to set the refresh token as a cookie and rely on the server-side to handle the redirect to the refresh endpoint.
B. It's not possible. The WebView's network stack is isolated and cannot be integrated with OkHttp's Authenticator mechanism.
C. Implement shouldInterceptRequest, proxy every request through OkHttp, and let the existing Authenticator handle 401 responses. This requires complex synchronous handling of the async OkHttp call.
D. Expose a @JavascriptInterface method that the web app's fetch interceptor can call when it receives a 401. The native method handles the token refresh and returns the new token to the JavaScript.

45 Consider a WebView in a Fragment. Which of the following is the most robust method to prevent WebView-related memory leaks, especially concerning the Context?

Building and Managing Web Apps in WebView Hard
A. In onDestroyView(), check if webView.parent is not null, cast it to ViewGroup and call removeView(webView), then call webView.destroy().
B. In onStop(), call webView.pauseTimers() and in onResume() call webView.resumeTimers().
C. Create the WebView programmatically in onCreateView using applicationContext instead of the Activity context.
D. Simply setting the WebView reference to null in onDestroyView() is sufficient for the garbage collector.

46 What is a key security implication of Android's multi-process WebView (active by default on Android O+) regarding the @JavascriptInterface?

Advance android programming Hard
A. The @JavascriptInterface object is cloned into the renderer process, leading to thread-safety issues if not designed to be stateless.
B. Multi-process WebView disables @JavascriptInterface by default for security, and it cannot be re-enabled.
C. All JavaScript calls to the native interface are executed on a dedicated background thread in the main app process, requiring manual synchronization with the UI thread.
D. Communication between the app process and the sandboxed renderer process is via IPC (Binder). Complex objects passed through the interface may be serialized, potentially leading to performance overhead or TransactionTooLargeException.

47 You have a web page with <meta name="viewport" content="width=device-width, initial-scale=1.0">. In your Android app, you set webView.settings.setUseWideViewPort(true) and webView.settings.setLoadWithOverviewMode(true). What will be the resulting behavior of the WebView's viewport?

Supporting Different Screens in web Apps Hard
A. The <meta> tag will take precedence. The WebView will render the page with a viewport width equal to the device's width in CSS pixels, and the setUseWideViewPort settings will be effectively ignored.
B. The WebView will first load the page in a wide viewport, and then the <meta> tag will trigger a re-layout to fit the device-width, causing a visible flash of content.
C. The WebView will use a wide viewport (typically 980px), and then setLoadWithOverviewMode will zoom out to fit this wide viewport entirely on the screen, ignoring the <meta> tag.
D. The settings will conflict, causing the WebView to fall back to a default behavior without a properly configured viewport.

48 You are implementing a custom WebChromeClient to handle file uploads from a <input type="file"> tag. Your implementation of onShowFileChooser correctly launches an Intent to pick a file. What is a critical, and often missed, step to ensure your implementation works correctly across all scenarios, including when the user cancels the file picker or the app is backgrounded?

Building and Managing Web Apps in WebView Hard
A. You must call ValueCallback.onReceiveValue(null) within the onShowFileChooser method before returning true.
B. You must ensure the WebView has the WRITE_EXTERNAL_STORAGE permission, even if you are only reading a file using the Storage Access Framework.
C. You must nullify the ValueCallback<Uri[]> member variable in onActivityResult if the result code is not Activity.RESULT_OK to prevent a stale callback from being used later.
D. The onShowFileChooser method must be synchronized to prevent race conditions if the user clicks the input multiple times quickly.

49 You observe that your WebView crashes intermittently, and the WebViewRenderProcessClient.onRenderProcessUnresponsive callback is triggered. Your app needs to be extremely resilient. What is the best strategy to recover from this state?

Advance android programming Hard
A. The operating system will automatically kill the unresponsive renderer and restart it. The app should just listen for onRenderProcessGone and show a sad face UI.
B. Call webView.reload() within the onRenderProcessUnresponsive callback to force the renderer to restart.
C. Remove the unresponsive WebView from the view hierarchy, destroy it, create a new WebView instance, add it back to the hierarchy, and reload the last known URL.
D. There is no recovery mechanism. The only option is to terminate the app process to ensure a clean state on next launch.

50 You are migrating a native app screen to a WebView. The native screen had complex back-press logic managed by OnBackPressedDispatcher. How do you correctly integrate the WebView's own history stack (canGoBack()/goBack()) with the Activity's back-press handling?

Migrating to WebView in Android Hard
A. Let the system handle it. WebView automatically integrates with the back-press dispatcher.
B. Create a custom WebView subclass that overrides onKeyDown and handles KeyEvent.KEYCODE_BACK internally, calling goBack() if its history is not empty.
C. In the Activity's onCreate, add an OnBackPressedCallback to the OnBackPressedDispatcher. In the callback's handleOnBackPressed method, check if (webView.canGoBack()) { webView.goBack(); } else { setEnabled(false); activity.onBackPressed(); }.
D. In the Activity's onBackPressed (deprecated), check if (webView.canGoBack()) { webView.goBack(); } else { super.onBackPressed(); }.

51 Your WebView needs to load a page that uses Service Workers for offline caching. Which WebViewClient callback is most critical for debugging and managing the interaction between the WebView and the Service Worker, especially for intercepting network requests handled by the worker?

Building and Managing Web Apps in WebView Hard
A. onPageFinished is the only callback that can reliably indicate if a Service Worker has been successfully registered and is controlling the page.
B. shouldInterceptRequest is still called, but the WebResourceRequest object will have a special flag indicating it was served from a Service Worker.
C. onLoadResource will be called for every resource, regardless of whether it came from the network, cache, or Service Worker.
D. None. WebViewClient callbacks like shouldInterceptRequest are bypassed for requests handled by a registered Service Worker. You must use the ServiceWorkerController and ServiceWorkerClient classes.

52 You are using a @JavascriptInterface to expose a native method postData(String json). This method is called frequently with large JSON payloads from JavaScript. You notice performance degradation. What is the most likely cause and the best optimization?

Advance android programming Hard
A. The frequent serialization/deserialization and IPC overhead between the renderer process and the app process for large strings is causing contention. A better approach would be to use WebView.postWebMessage with WebMessagePort for more efficient, dedicated communication.
B. The String object in Java is creating too much garbage collection pressure. You should use a StringBuilder in the interface method signature.
C. The @JavascriptInterface runs on the UI thread, and processing large strings blocks it. The solution is to make the postData method synchronized.
D. The V8 JavaScript engine is slow at serializing large JSON objects. The JSON should be compressed in JavaScript before being sent.

53 To achieve a pixel-perfect layout where a 1px CSS border in your web content renders as exactly one physical pixel on a xxhdpi device (which has a density of 3.0), what calculation and communication between JavaScript and native code is required?

Supporting Different Screens in web Apps Hard
A. Use 1dp as the unit in a stylesheet injected from the native side, as WebView understands dp units.
B. This is handled automatically by the WebView if you set <meta name="viewport" content="width=device-width, initial-scale=1">.
C. In Android, get the density and pass it to JS. JS should then use a CSS transform: scale(1/density) on the container element.
D. In Android, get the display density via context.resources.displayMetrics.density. Pass this value (e.g., 3.0) to JavaScript via a JS interface. JavaScript should then set the border width to (1.0 / window.devicePixelRatio) + 'px', which will be 0.333px.

54 What is the fundamental difference in purpose between WebViewClient.onPageCommitVisible() and WebChromeClient.onProgressChanged()?

Building and Managing Web Apps in WebView Hard
A. onPageCommitVisible is called once when the content of the page becomes visible to the user, marking the end of the 'above-the-fold' render. onProgressChanged is called multiple times during the page load to report the percentage of resources loaded.
B. They are largely synonymous, but onPageCommitVisible is part of the newer WebViewClient API and is more reliable than waiting for onProgressChanged to reach 100.
C. onPageCommitVisible is called when the page is fully interactive (DOM ready and JavaScript loaded), while onProgressChanged reaching 100 means all subresources (images, scripts) have finished downloading.
D. onProgressChanged reports the network loading progress, while onPageCommitVisible reports the DOM parsing progress.

55 Your WebView must securely load content from a server that uses a client SSL certificate for authentication. How do you configure the WebView to provide this certificate during the TLS handshake?

Advance android programming Hard
A. Install the certificate into the Android system's user credential storage. The WebView will automatically pick it up for the specified host.
B. Set the certificate directly using a method like webView.getSettings().setClientCertificate(pathToCert, password).
C. You must use shouldInterceptRequest, proxy the request through a custom SSLSocketFactory (e.g., with OkHttp) that is configured with your KeyStore, and return the response.
D. Implement WebViewClient.onReceivedClientCertRequest and in your implementation, call handler.proceed(privateKey, certificateChain) with the appropriate certificate from your app's KeyStore.

56 While migrating a feature to a WebView, you need to maintain two-way data synchronization between a native component (e.g., a SeekBar) and a JavaScript element in the WebView. Which of the following describes the most efficient and responsive implementation?

Migrating to WebView in Android Hard
A. Native -> JS: Use evaluateJavascript. JS -> Native: Use a @JavascriptInterface callback. This provides a direct, event-driven communication channel in both directions.
B. Both Directions: Use frequent polling, where the native side calls evaluateJavascript every 100ms to get the web value, and JavaScript calls the native interface every 100ms to get the native value.
C. Both Directions: Write the shared state to a local file that both the native code and a fetch call in JavaScript can access.
D. Native -> JS: Use webView.loadUrl("javascript:updateValue(...)"). JS -> Native: Have JavaScript change the document title (document.title = ...) and listen for it in WebChromeClient.onReceivedTitle().

57 You set a strict Content Security Policy (CSP) via HTTP headers for your web app. Now, you need to execute a specific, trusted script from your native Android code using evaluateJavascript. The CSP blocks inline scripts (script-src 'self'), causing the evaluation to fail. What is the correct way to allow this single execution without globally weakening your CSP?

Building and Managing Web Apps in WebView Hard
A. Use webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW) which also bypasses certain CSP restrictions.
B. Generate a nonce (a random, one-time-use string) on the native side. When loading the WebView, inject this nonce into the CSP header (script-src 'self' 'nonce-YOUR_NONCE'). Then, when calling evaluateJavascript, wrap your script in a <script nonce="YOUR_NONCE">...</script> tag and evaluate that.
C. The CSP cannot be bypassed from the native side. You must modify the server's HTTP header to include 'unsafe-inline'.
D. Intercept the page load in shouldInterceptRequest, manually download the HTML, remove the CSP header, and then use webView.loadDataWithBaseURL to load the modified content.

58 Your WebView displays content that needs to adapt when the user enters Android's split-screen mode. Standard CSS @media queries based on viewport width are not sufficient as the width might not change significantly, but the aspect ratio and available space do. How can the web content be reliably notified of the native app entering or exiting split-screen mode?

Supporting Different Screens in web Apps Hard
A. The web app can use the JavaScript Page Visibility API; the page will become 'hidden' when entering split-screen mode.
B. Override the Activity's onMultiWindowModeChanged method. Inside it, call webView.evaluateJavascript("document.dispatchEvent(new CustomEvent('multiWindowChanged', { detail: { isInMultiWindow: true } }))") to inform the web app.
C. The WebView's user-agent string is automatically updated with multi-window information, which JavaScript can parse.
D. This is not possible. The web content is isolated from the native windowing state.

59 When using setDownloadListener to manage file downloads with the system DownloadManager, a user reports that downloads are failing for URLs that require an authentication cookie. Why does this happen and what is the solution?

Advance android programming Hard
A. The issue is with the contentDisposition string. It must be parsed correctly to extract the filename before passing the request to the DownloadManager.
B. You need to grant the android.permission.PROCESS_OUTGOING_CALLS permission for the DownloadManager to share authentication state with the app.
C. The DownloadManager runs in a separate system process and does not have access to the WebView's cookie store. You must manually retrieve the cookie for the URL using CookieManager.getInstance().getCookie(url) and add it as an HTTP header to the DownloadManager.Request using addRequestHeader("Cookie", cookieValue).
D. DownloadManager does not support authenticated downloads. You must implement the entire download logic manually using an HTTP client like OkHttp in a foreground Service.

60 You are debugging a complex web application in a WebView and suspect a race condition between multiple JavaScript files. You want to debug the JavaScript code using Chrome DevTools. Which statement about setting up remote debugging is most accurate?

Building and Managing Web Apps in WebView Hard
A. You need to add <uses-permission android:name="android.permission.INTERNET"/> and android:usesCleartextTraffic="true" to the manifest to allow the debugging socket to connect.
B. You must call the static method WebView.setWebContentsDebuggingEnabled(true) and ensure your app's debuggable flag is true in the manifest. The device must then be connected via USB with debugging enabled to appear in chrome://inspect.
C. You must implement a custom WebChromeClient and override onConsoleMessage to manually forward logs to Logcat, as direct inspection is not possible.
D. Remote debugging is enabled by default in all WebView instances. You just need to connect the device and open Chrome DevTools.