Question : Javascript is enabled by default in a WebView
1. True 2. False
Correct Answer : 2 Explanation: If the web page you plan to load in your WebView use JavaScript, you must enable JavaScript for your WebView. Once JavaScript is enabled, you can also create interfaces between your application code and your JavaScript code.
Correct Answer : 3 Explanation: Using JavaScript in WebView If the web page you plan to load in your WebView use JavaScript, you must enable JavaScript for your WebView. Once JavaScript is enabled, you can also create interfaces between your application code and your JavaScript code.
Enabling JavaScript
JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView. You can retrieve WebSettings with getSettings(), then enable JavaScript with setJavaScriptEnabled().
For example:
WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); WebSettings provides access to a variety of other settings that you might find useful. For example, if you're developing a web application that's designed specifically for the WebView in your Android application, then you can define a custom user agent string with setUserAgentString(), then query the custom user agent in your web page to verify that the client requesting your web page is actually your Android application.
Question : What two methods you have to override when implementing Android context menus?
1. onCreateOptionsMenu, onCreateContextMenu
2. onCreateContextMenu, onContextItemSelected
3. onCreateOptionsMenu, onOptionsItemSelected
4. onCreateOptionsMenu, onContextItemSelected
Correct Answer : 2 Explanation: onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) This method is triggered when the screen is long pressed and context menu view is being built menu - The actual context menu being built, using which we can set its properties.
onContextItemSelected(MenuItem item) This is called whenever an item in the context menu is selected and the interface MenuItem provides necessary details on the selected item. Through which we can write our own functionality to be perform based on item selection.