Premium

Associate Android Developer Certification Questions and Answer (Dumps and Practice Questions)



Question : An AsyncTask can be cancelled anytime from any thread.

 : An AsyncTask can be cancelled anytime from any thread.
1. True
2. False

Correct Answer : 1
Explanation: AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

AsyncTask is designed to be a helper class around Thread and Handler and does not constitute a generic threading framework. AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent package such as Executor, ThreadPoolExecutor and FutureTask.

An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute.
Cancelling a task
A task can be cancelled at any time by invoking cancel(boolean). Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(Object), instead of onPostExecute(Object) will be invoked after doInBackground(Object[]) returns. To ensure that a task is cancelled as quickly as possible, you should always check the return value of isCancelled() periodically from doInBackground(Object[]), if possible (inside a loop for instance.)




Question : Which of the following is NOT true about onMeasure() method of class View?

 : Which of the following is NOT true about onMeasure() method of class View?
1. It measures the view and its contents to determine the measured width and height.

2. It is invoked by measure().

3. When overriding this method, a developer must call setMeasuredDimension().

4. It takes three parameters: the height, width, and the depth of the view.

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!




Question : Which of the following Activity life-cycle methods is invoked when a dialog is shown?

 : Which of the following Activity life-cycle methods is invoked when a dialog is shown?
1. onPause()

2. onCreate()

3. onStop()

4. onDestroy()

Correct Answer : 1
Explanation: During normal app use, the foreground activity is sometimes obstructed by other visual components that cause the activity to pause. For example, when a semi-transparent activity opens (such as one in the style of a dialog), the previous activity pauses. As long as the activity is still partially visible but currently not the activity in focus, it remains paused.

However, once the activity is fully-obstructed and not visible, it stops (which is discussed in the next lesson).

As your activity enters the paused state, the system calls the onPause() method on your Activity, which allows you to stop ongoing actions that should not continue while paused (such as a video) or persist any information that should be permanently saved in case the user continues to leave your app. If the user returns to your activity from the paused state, the system resumes it and calls the onResume() method.


Related Questions


Question : To create a customized Adapter for a compound list item layout, you should:

 : To create a customized Adapter for a compound list item layout, you should:
1. Extend class android.widget.Adapter or any of its descendants then override method getView()

2. Extend class android.widget.ListView or any of its descendants, then override method getView()

3. Access Mostly Uused Products by 50000+ Subscribers

4. Extend class android.widget.Adapter or any of its descendants, then override method getAdapterView().


Question : When publishing an update to your application to the market, the following must be taken into consideration:

 : When publishing an update to your application to the market, the following must be taken into consideration:
1. The package name must be the same, but the .apk may be signed with a different private key.

2. The package name does not have to be the same and the .apk can be signed with a different private key.

3. Access Mostly Uused Products by 50000+ Subscribers

4. The package name does not have to be the same, but the .apk must be signed with the same private key.


Question : Which of these is the incorrect method for an Application to save local data?

 : Which of these is the incorrect method for an Application to save local data?
1. Extend PreferencesActivity and save in an XML file.

2. Save as a file in the local file system.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Save in the hash table file using the Dictionary class.


Question : Which UI does the following code builds?
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >