Answer: C px - pixels, dp - density independent pixels, dip - density independent pixels, sp - scale independent pixels
Description: px - is meant for absolute pixels. This is used if you want to give in terms of absolute pixels for width or height. Not recommended.
dp/ dip - both mean same, density independent pixels. This is alternative of px. Generally we never use px because it is absolute value. If you use px to set width or height, and if that application is being downloaded into different screen sized devices, then that view will not stretch as per the screen original size. dp is highly recommended to use in place of px.
Use dp if you want to mention width and height to grow & shrink dynamically based on screen sizes.
if we give dp/dip, android will automatically calculate the pixel size on the basis of 160 pixel sized screen.
sp - Scale independent pixels. when mentioning the font sizes to fit for various screen sizes, use sp. This is similar to dp.Use sp especially for font sizes to grow & shrink dynamically based on screen sizes.
dpi- dots per inch. It is the resolution factor. More the dpi better and higher the screen resolution.
Math logic behind it:
1dp = 1px in 160 dpi screen. Means 1 dp is equal to 1physical px of a device having 160 dots per inch.
so no of dynamic pixles for a given dp is = (dp's)*(density/160).
For example on 240dpi screen 1dp = 1.5px (physical pixels)
Answer: B it is to align the view content either right/top/bottom/center with in that view.
Description: android:gravity property is used to align the view content either right/top/bottom/center/.. with in that view.
Answer: A linear layout - arranges element in either vertical or horizontal fashion. Relative layout - arranges elements in relative to each other.
Description: linear layout - arranges child element in either vertical or horizontal fashion.
Relative layout - arranges child elements in relative to each other.
Important properties of Relative Layout:
1. android:below
2. android:above
3. android:toRightof
4. android:toLeftof
Answer: C both i and ii
Description: Activity can be killed programatically in two ways. finish() or finishActivity(int requestcode).
finish() - can be used by an activity to kill itself.
finishActivity(int requestcode) - Force finish another activity that you had previously started with startActivityForResult(Intent intent, int requestcode); This function will let the parent activity to kill the child activity, which it has started previously.
Answer: D can be any of the above based on the situation.
Description: Configuration change : is either orientation change(phone rotation), or language settings change.
In case of configuration change, android will forcefully kill your activity and recreates it, unless you are not handling configuration changes on your own programmatically.
When android kills your activity due to configuration changes, it makes sure that it will definitely call onPause() and onSaveInstanceState. But there is no guarantee about call onStop and onDestroy. But android documentation doesn't say that it will not call onStop and onDestroy. it depends.
Life cycle in the case of configuration changes can be any of the option 1, or 2, or 3, based on the situation. some times it might not kill activity at all if programmer is handling configuration changes programmatically, which is not a standard way to do.
Answer: B horizontal & vertical linear layout
Description: two types of linear layouts are available. horizontal & vertical.
Linear Layout: Linear layout can have only two orientations either vertical or horizontal.It will align the child views in the linear fashion either vertically or horizontal.
By default linear layouts will use horizontal, if you don't specify any orientation.
Answer: B because user is eagerly waiting for next activity to show up
Description: onPause() will be called as the first indication that user is moving away from your activity, that means intentionally user is moving to next screen, so more the time you hold control in onPause() more it will irritate user. so don't hold control here for too much of time.
Answer: B if any UI changes happened while it is in invisible state, updated it in this function
Description: onRestart() will be called, after onStop(). when onStop is called it means your activity is in invisible state, during that time if any ui changes happens which is not visible to user, update all those changes to user in onRestart()
Answer: C option 2 is right, because array adapter takes only lists
Description: array adapter takes - lists (arraylists);
cursor adapter takes - cursor which is returned from database tables upon querying.
Answer: B getCount(), getView(), getItem(), getItemId()
Description: If one is implementing custom adapter by extending BaseAdapter, then he or she has to give implementation of all 4 functions mentioned getView(), getItem(), getCount(), getItemId().
Answer: C Extend Either one of the conceret Adapters or BaseAdapter
Description: To create a own custom adapter, one can extend BaseAdapter, or can extend any of the existing concrete adapters like ArrayAdapter, SimpleCursorAdatper etc..
Note: we can also extend or implement other adapter interfaces, but it is not so useful. Generally extending BaseAdapter is enough to create our own custom adapter.
Answer: B bridge between source and adapter views
Description: Adapter Design Patterns:
1. If destination is expecting one kind of input and source is giving one kind of input then we have to use adapters to convert source into destination.
2. Whenever you change the source we have to use a different kind of adapter.
adapter design pattern is used for bridging between source and adapter views.
Functionalities of Adapter:
It takes the input from source and gives to the destination.
ADAPTER VIEW:
Any view that is getting input from any adapter is called as Adapter View.
List view is an example of adapter view.
List view generally will contain vertically scrollable list of items.
NOTE: Source should not directly communicate with destination (Adapter view).
FUNCTIONALITIES OF ADAPTERS IN AANDROIDANDROIDNDROID:
1. Adapters will take inputs from source and gives to the destination.
2. If there is any change in the source and if we notify to the adapter then adapter will go and modify the destination.
3. Adapter will take each data item from source and prepare a view and dispatches that view to the destination.
Examples for adapters:
eg1 : If you want to display data from array list into listview, then we use arrayadapter in android.
eg2 : if you want to display data from database into a listview, then we use cursoradapter in android.
Answer: D any view that takes input from adapter is called as adapter view. eg:listview, gallery, spinner, gridview, etc..
Description: any view that takes input from adapter is called as adapter view. eg:listview, gallery, spinner, gridview, etc..
Answer: D option 3 is true because, if user is visiting an app frequently, then it has to be loaded many times.
Description: Generally after calling onDestroy(), app will be removed from memory. But there is an exception for this rule. If user is visiting an app very frequently then it has to be loaded into memory very frequently. to avoid this over head for the system, android may choose to keep that app in memory even after onDestroy(). This is called "empty process". Process which is killed but still in memory.
Answer: B onStop()
Description: When we press home button any activity, that will be moved to back ground state (invisible state), so it calls onStop() on that activity
Answer: B Bundle contain previous savedInstantceState
Description: Bundle is a data holder, which holds data to be passed between activities.
In case of forceful closing of an activity, android will save all its UI states and transient states so that they can be used to restore the activity's states later. This saved states will be passed via Bundle in onCreate() function to restore its states once android recreates a killed activity.
EG: this will happen in case of low memory or configuration changes like rotating the phone
onSaveInstanceState():
This function will be called by aAndroidAndroidndroid before “ompause” or after “onpause” if aAndroidAndroidndroid is forcefully killing your activity. In this function we have to save all your activity states.
onRestoreInstanceState():
This function will be called after “onStart”.
Answer: A Intent in = new Intent();
in.setType("image/*");
in.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(in, 0);
Description: Intent in = new Intent();
in.setType("image/*");
in.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(in, 0);
Answer: B array adapter, cursor adapter, expandable list adapter, etc..
Description: adapter examples: arrayadapter , base adapter, cursor adapter, expandable list adapter,..
Answer: C onResume()
Description: Since heavy weight functions take too much of battery power, better do it just before your activity is ready to take user events. so do it in onResume().
Answer: C when onStop() is called, then activity is still in memory and all its states and variables are intact.
Description: when onStop() is called, then activity is still in memory and all its states and variables are intact.