android interview questions and answers paper 415 - skillgunNote: Paper virtual numbers may be different from actual paper numbers . In the page numbers section website displaying virtual numbers .
Which method need to be called to shut down an activity, itself?
None are correct.
Activity can be killed programatically in two ways. finish() or finishActivity(intent); intent should be matching with your activity.
finish() - can be used to kill itself.
finishActivity() - is to allow others to kill your activity.
Which of the following are true about enabling/disabling menu items from an Activity class?
The menu items in an Android application cannot be disabled.
onCreateOptionsMenu can be used to enable/disable some menu items in an Android application.
onPrepareOptionsMenu can be used to enable/disable some menu items in an Android application.
onShowOptionsMenu can be used to enable/disable some menu items in an Android application.
onCreateOptionsMenu function will be called only once when application gets loaded for the first time.
After that it will not be called.
onPrepareOptionsMenu will be called each time user clicks menu button.
If you want to enable or disable some of the menu items, then use this function.
Which of the following are the layouts available in android ?
i. Frame Layout
ii. Table Layout
iii. Linear Layout
iv. Relative Layout
i, ii, iii
What is the difference between Activity context and Application context ?
The activity instance is tied to the lifecycle of an application while the application instance is tied to the lifecycle of an application.
The activity instance is tied to the lifecycle of an activity while the application instance is tied to the lifecycle of an application.
activity context means : this pointer in activity.
application context means : process context which can be obtained by getApplicationContext() function.
this pointer always points to current class object, app context will point to entire process. there is only one app context. if you want to use some control whose life time is through out your application life time then go for app context, else use this pointer (activity context).
What is the difference between view and viewgroup in android?
View is a basic building block of UI (User Interface) in android. A view is a small rectangular box which responds to user inputs. Eg: EditText, Button, CheckBox, etc..
ViewGroup is a invisible container of other views (child views) and other viewgroups. Eg: LinearLayout is a viewgroup which can contain other views in it.
ViewGroup is a special kind of view which is extended from View as its base class. ViewGroup is the base class for layouts.
all are true
What is the difference between margin and padding in android?
Margin specifies the extra space left on all four sides of a view. Margin space is generally outside the view's bounds. To leave space on left side use android:margin_left, to leave space on other sides use android:layout_marginRight, android:layout_marginTop, android:layout_marginBottom etc..
Padding is used to offset the content of a view by specifying pixels. For example a left padding of 2 wil push views content 2 pixels right side of the left edge. Use android:padding
android:paddingTop to set padding on various sides of the content of that view.
both options are true
Margin is the offset for the content of the view, and padding is the space outside the view's bounds. Other wise both option 1 and option 2 are correct.
Suppose MyView is a class derived from View and mView is a variable of type MyView. Which of the following should be used to display mView when the Android application is started?
Call setContentView(mView) in the onStart() of the main application class.
Call setCurrentView(mView) in the onCreate() of the main application class.
Call setContentView(mView) in the onCreate() of the main application class.
Call setCurrentView(mView) in the startApp() of the main application class.
Which of the following are appropriate for saving the state of an android applications?
Activity.onPause() is the only last guaranteed function to be called in activity life cycle, before killing an activity in all the scenarios.
So save all your persistent data in onPause().
How does android achieve seamlessness. What is the meaning of seamlessness?
by handling onSaveInstanceState. Seamlessness means uninterrupted flow of application.
by handling configuration changes, seamless meaning is same as option 1
by handling low memory scenarios, seamlessness meaning is same as 1.
all options are true
seamlessness means un-interrupted flow of an application. No matter what is happening to your application, user should not feel that disturbance. these disturbances may happen in case of low memory, and configuration changes where android will and recreate the activity. but these changes should not be visible to the user and should not disturb user. this can be done by handling these conditions in onSaveInstantnceState() in all activities.
What does the flag FLAG_ACTIVITY_NEW_TASK do here?
Intent in = new Intent();
It will start a new activity with matching intent filter, in a new task always.
It will start a new activity with matching intent filter, in a new task only if that corresponding task is not in memory now.
It will start a new activity with matching intent filter, in old task always. here old task means task in which the current activity is running which has started new activity.
This will start a new activity in a new task, where only this activity will be there in that task and no other components. if at all new components are launched from this new activity, they will be launched in a different task.
Description from developer android documentation:
If this flag is set, then this activity will become the start of a new task on this history stack.
When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in.
What does the flag FLAG_ACTIVITY_SINGLE_INSTANCE do here?
Intent in = new Intent();
What are the indirect sub classes of Activity class?
ii & iii
i, ii, & iii
What is android activity creator tool?
tool used to create an activity
command line tool or batch file to create android project.
it is used to compile the android java files into .class file
Note : this tool is deprecated and no more in use.
What is activity manager in android?
Activity manager is used to monitor and manage activity stack.
we can use activity manager to retrieve information about tasks that user has visited recently, information about currently running processes, information about perticulare task that is currently running, etc..
What is activity animation in android?
playing animtion in an activity is called as activity animation.
Applying transition and scaling animations while moving from one activity to other activity is called as activity animation, to make it appear as if they are sliding and zooming in and out.
both are true
What is activity transition animation in android? How to do activity transition animation?
A Transition is a mechanism to automatically animate changes that occur when a new scene is entered.
When a transition is applied while moving from one activity to other activity, then new activity will appear as if it is sliding from right to left. While moving in the new activity, you can apply some animation to old activity to apear as if it is fading out by using alpha.
A sample code:
Go to resources->anim folder-> create opening_trans.xml
Go to resources->anim folder-> create closing_scale.xml
android:pivotY="50%p" android:duration="@android:integer/config_mediumAnimTime" />
Go to your activity
protected void onCreate(Bundle savedInstanceState)
//apply opening animation
In android how to hide keyboard?
Programatically we can close virtual keyboard with below code.
InputMethodManager inputManager = (InputMethodManager)
Programatically we can close virtual keyboard with below code.
If it is not through programming, a mobiler user can hide the virtual keyboard by swiping keyboard from top to bottom very quickly. Many of the virtual keyboards support this operation to hide.
In android how to download youtube videos?
What are the different screen sizes available or supported in android?
android supports 4 variants of screen sizes: small, normal, large, and extra large
xlarge screens are at least 960dp x 720dp resolution
large screens are at least 640dp x 480dp resolution
normal screens are at least 470dp x 320dp resolution
small screens are at least 426dp x 320dp resolution
In android how to get difference between two dates?
Assume that two dates are d1, and d2.
long dif_dates = d1.getTime() - d2.getTime();
long secs = dif_dates / 1000;
long mins = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
assume that you have two dates secondDate and firstDate.
long dateDif = secondDate.getTime() - firstDate.getTime();
long difference = TimeUnit.MILLISECONDS.toSeconds(dateDif);
both are true. But second option gives difference in terms of seconds, where as first one in terms of days, hours.
Back To Top