1

Which method need to be called to shut down an activity, itself?

  • onDestroy()
  • finish()
  • finishActivity()
  • None are correct.

Answer: B finish()
Description: 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.

2

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.

Answer: C onPrepareOptionsMenu can be used to enable/disable some menu items in an Android application.
Description: 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.

3

Which of the following are the layouts available in android ?

  • i. Frame Layout
  • ii. Table Layout
  • iii. Linear Layout
  • iv. Relative Layout
  • i
  • i, ii
  • i, ii, iii
  • All
4

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.
  • No difference.
  • None are correct.

Answer: B The activity instance is tied to the lifecycle of an activity while the application instance is tied to the lifecycle of an application.
Description: 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).

5

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

Answer: D all are true
Description:

6

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..
  • 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..
    android:paddingBottom
    android:paddingLeft
    android:paddingRight
    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.

Answer: C both options are true
Description:

7

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.

Answer: C Call setContentView(mView) in the onCreate() of the main application class.
Description:

8

Which of the following are appropriate for saving the state of an android applications?

  • Activity.onFreeze()
  • Activity.onStop()
  • Activity.onPause()
  • Activity.onDestroy()

Answer: C Activity.onPause()
Description: 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().

9

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

Answer: D all options are true
Description: 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.

10

What does the flag FLAG_ACTIVITY_NEW_TASK do here?

Intent in = new Intent();
in.setAction("com.android.myproject.MYACTION");
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
  • 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.

Answer: B It will start a new activity with matching intent filter, in a new task only if that corresponding task is not in memory now.
Description: 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.

11

What does the flag FLAG_ACTIVITY_SINGLE_INSTANCE do here?

Intent in = new Intent();
in.setAction("com.android.myproject.MYACTION");
in.setFlags(Intent.FLAG_ACTIVITY_SINGLE_INSTANCE);
startActivity(in);
  • 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.

Answer: D 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:

12

What are the indirect sub classes of Activity class?

  • i. ActionBarActivity
  • ii. LauncherActivity
  • iii. PreferenceActivity
  • iv. TabActivity
  • i
  • ii & iii
  • i, ii, & iii
  • all
13

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
  • none

Answer: B command line tool or batch file to create android project.
Description: Note : this tool is deprecated and no more in use.

14

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..
  • both options are true
  • none

Answer: C both options are true
Description:

15

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
  • none

Answer: B 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.
Description:

16

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

    <set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%"
    android:toXDelta="0%"
    android:duration="@android:integer/config_mediumAnimTime" />
    </set>

    Go to resources->anim folder-> create closing_scale.xml

    <set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale android:fromXScale="80%p"
    android:toXScale="100%p"
    android:fromYScale="80%p"
    android:toYScale="100%p"
    android:pivotX="50%p"
    android:pivotY="50%p"
    android:duration="@android:integer/config_mediumAnimTime" />

    <alpha android:fromAlpha="0.5"
    android:toAlpha="1.0"
    android:duration="@android:integer/config_mediumAnimTime"/>
    </set>

    Go to your activity
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    //apply opening animation
    overridePendingTransition(R.anim.opening_trans,R.anim.closing_scale);
    }
  • all are true

Answer: D all are true
Description:

17

In android how to hide keyboard?

  • Programatically we can close virtual keyboard with below code.
    InputMethodManager inputManager = (InputMethodManager)
    this.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
    InputMethodManager.HIDE_NOT_ALWAYS);
  • Programatically we can close virtual keyboard with below code.
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  • 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.
  • all are true

Answer: D all are true
Description:

18

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
  • both options are true
  • none

Answer: C both options are true
Description:

19

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.
  • none

Answer: C both are true. But second option gives difference in terms of seconds, where as first one in terms of days, hours.
Description: