Question : Which of the following classes is used by Intent to transfer data between different android components?
1. Extras
2. Bundle
3. Parcelables
4. PendingIntent
Correct Answer : 2 Explanation: The data of the Intent is described as a Bundle. The Bundle object is used to pass data between activities. This data can be retrieved from the Intent through the getExtras() method. A Bundle object is actually a hash control that stores key and value pairs.
Question : Which of the following is true about implicit intents? (Choose two)
A. They do not have a component specified B. They have components specified to run an exact class. C. They must include information that allows Android system to choose the best component to run. D. They must contain extra information saved in a Bundle object. 1. A,B 2. B,C 3. C,D 4. A,D 5. A,C
Correct Answer : 5 Explanation: Intents are asynchronous messages which allow application components to request functionality from other Android components. Intents allow you to interact with components from the same applications as well as with components contributed by other applications. For example, an activity can start an external activity for taking a picture.
Intents are objects of the android.content.Intent type. Your code can send them to the Android system defining the components you are targeting. For example, via the startActivity() method you can define that the intent should be used to start an activity.
An intent can contain data via a Bundle. This data can be used by the receiving component. Different types of intents Android supports explicit and implicit intents. An application can define the target component directly in the intent (explicit intent) or ask the Android system to evaluate registered components based on the intent data (implicit intents). Explicit Intents : Explicit intents explicitly define the component which should be called by the Android system, by using the Java class as identifier. The following shows how to create an explicit intent and send it to the Android system. If the class specified in the intent represents an activity, the Android system starts it.
Intent i = new Intent(this, ActivityTwo.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo"); Explicit intents are typically used within on application as the classes in an application are controlled by the application developer. Implicit Intents : Implicit intents specify the action which should be performed and optionally data which provides content for the action. For example, the following tells the Android system to view a webpage. All installed web browsers should be registered to the corresponding intent data via an intent filter.
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.hadoopexam.com")); startActivity(i); If an implicit intent is sent to the Android system, it searches for all components which are registered for the specific action and the fitting data type.If only one component is found, Android starts this component directly. If several components are identified by the Android system, the user will get a selection dialog and can decide which component should be used for the intent. A component can register itself for actions. Data transfer to the target component An intent contains certain header data, e.g., the desired action, the type, etc. Optionally an intent can also contain additional data based on an instance of the Bundle class which can be retrieved from the intent via the getExtras() method. You can also add data directly to the Bundle via the overloaded putExtra() methods of the Intent objects. Extras are key/value pairs. The key is always of type String. As value you can use the primitive data types (int, float, ...) plus objects of type String, Bundle, Parceable and Serializable. The receiving component can access this information via the getAction() and getData() methods on the Intent object. This Intent object can be retrieved via the getIntent() method.The component which receives the intent can use the getIntent().getExtras() method call to get the extra data. That is demonstrated in the following code snippet.
Question : Which of the following classes should be extended to create a custom view?
1. View
2. ViewGroup
3. Context
4. Activity
Correct Answer : 1 Explanation: A well-designed custom view is much like any other well-designed class. It encapsulates a specific set of functionality with an easy to use interface, it uses CPU and memory efficiently, and so forth. In addition to being a well-designed class, though, a custom view should:
Conform to Android standards Provide custom styleable attributes that work with Android XML layouts Send accessibility events Be compatible with multiple Android platforms. The Android framework provides a set of base classes and XML tags to help you create a view that meets all of these requirements. This lesson discusses how to use the Android framework to create the core functionality of a view class. All of the view classes defined in the Android framework extend View. Your custom view can also extend View directly, or you can save time by extending one of the existing view subclasses, such as Button.
To allow Android Studio to interact with your view, at a minimum you must provide a constructor that takes a Context and an AttributeSet object as parameters. This constructor allows the layout editor to create and edit an instance of your view.
class PieChart extends View { public PieChart(Context context, AttributeSet attrs) { super(context, attrs); } }