Question : Which of the following is a valid sequence of invokes to Activity lifecycle methods? (Select Two) A. onCreate > onStart > onResume > onPause> onStop> onCreate B. onCreate > onStart > onResume > onPause> onStop>onRestart C. onCreate > onStart > onResume > onPause> onStop>onDestroy D. onCreate > onStart > onResume > onPause> onStop>onResume 1. A,B 2. B,C 3. C,D 4. A,D
Correct Answer : 2 Explanation: The Activity class defines the following call backs i.e. events. You don't need to implement all the callbacks methods. However, it's important that you understand each one and implement those that ensure your app behaves the way users expect.
Callback Description onCreate() This is the first callback and called when the activity is first created. onStart() This callback is called when the activity becomes visible to the user. onResume() This is called when the user starts interacting with the application. onPause() The paused activity does not receive user input and cannot execute any code and called when the current activity is being paused and the previous activity is being resumed. onStop() This callback is called when the activity is no longer visible. onDestroy() This callback is called before the activity is destroyed by the system. onRestart() This callback is called when the activity restarts after stopping it.
Question : Which of the following is true about this code snippet? (Choose two)
Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:555-1234")); startActivity(intent);
A. This is an explicit intent that start the system's dialer. B. The system will not dial the number without adding permission CALL_PHONE. C. The system will perform an intent resolution to start the proper activity. D. The code will not compile. 1. A,B 2. B,C 3. C,D 4. A,D 5. A,D
Correct Answer : 2 Explanation: You can use Intent.ACTION_DIAL instead of Intent.ACTION_CALL. This shows the dialer with the number already entered, but allows the user to decide wether to actually make the call or not. ACTION_DIAL does not require the CALL_PHONE permission. This demo will helpful for you On call button click: Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number")); startActivity(intent); Permission in Manifest: Intent.ACTION_DIAL instead Intent.ACTION_CALL. For example: try { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone_number)); startActivity(intent); } catch (Exception e) { } And in this case you can completely remove these tags from AndroidManifest.xml: given the permission in the manifest file
and inside your activity
Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:123456789")); startActivity(callIntent);
Question : Which of the following are layout-related methods called by the framework on views, and you can override them when customizing a view? (Choose two)
A. onMeasure(). B. onDraw(). C. onKeyUp(). D. onSizeChanged(). 1. A,B 2. B,C 3. C,D 4. A,D
Correct Answer : 4 Explanation: onMeasure() is your opportunity to tell Android how big you want your custom view to be dependent the layout constraints provided by the parent; it is also your custom view's opportunity to learn what those layout constraints are (in case you want to behave differently in a match_parent situation than a wrap_content situation). These constraints are packaged up into the MeasureSpec values that are passed into the method. Here is a rough correlation of the mode values:
EXACTLY means the layout_width or layout_height value was set to a specific value. You should probably make your view this size. This can also get triggered when match_parent is used, to set the size exactly to the parent view (this is layout dependent in the framework). AT_MOST typically means the layout_width or layout_height value was set to match_parent or wrap_content where a maximum size is needed (this is layout dependent in the framework), and the size of the parent dimension is the value. You should not be any larger than this size. UNSPECIFIED typically means the layout_width or layout_height value was set to wrap_content with no restrictions. You can be whatever size you would like. Some layouts also use this callback to figure out your desired size before determine what specs to actually pass you again in a second measure request. The contract that exists with onMeasure() is that setMeasuredDimension() MUST be called at the end with the size you would like the view to be. This method is called by all the framework implementations, including the default implementation found in View, which is why it is safe to call super instead if that fits your use case.
Granted, because the framework does apply a default implementation, it may not be necessary for you to override this method, but you may see clipping in cases where the view space is smaller than your content if you do not, and if you lay out your custom view with wrap_content in both directions, your view may not show up at all because the framework doesn't know how large it is! Android doesn't know the real size at start, it needs to calculate it. Once it's done, onSizeChanged() will notify you with the real size.
onSizeChanged() is called once the size as been calculated. Events don't have to come from users all the time. In this example when android change the size, onSizeChanged() is called. Same thing with onDraw(), when the view should be drawn onDraw() is called.
onMeasure() is called automatically right after a call to measure()