Android Studio Viva Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

1) When the development of android is started?

> Android Inc. was founded in Palo Alto, California, in October 2003
by Andy Rubin, Rich Miner, Nick Sears, and Chris White.

2) 10 features of android
> Beautiful UI
Android OS basic screen provides a beautiful and intuitive user interface.
Connectivity
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and WiMAX.
Storage
SQLite, a lightweight relational database, is used for data storage purposes.
Media support
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI,
Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.
Multi-touch
Android has native support for multi-touch which was initially made available in
handsets such as the HTC Hero.
Multi-tasking
User can jump from one task to another and same time various application can run
simultaneously.
Resizable widgets
Widgets are resizable, so users can expand them to show more content or shrink
them to save space.
Multi-Language
Supports single direction and bi-directional text.
Wi-Fi Direct
A technology that lets apps discover and pair directly, over a high-bandwidth peer-to-
peer connection.
Android Beam
A popular NFC-based technology that lets users instantly share, just by touching two
NFC-enabled phones together.
3) android is based on which kernel
> Android is a mobile operating system based on a modified version of
the Linux kernel and other open-source software, designed primarily for
touchscreen mobile devices such as smartphones and tablets.

4) what is the license name for android


> It is free and open source software; its source code is known
as Android Open Source Project (AOSP), which is
primarily licensed under the Apache License

5) steps for creating android project

> To create your new Android project, follow these steps:


1. Install the latest version of Android Studio.
2. In the Welcome to Android Studio window, click Create New Project.

Figure 1. Android Studio welcome screen

If you have a project already opened, select File > New > New Project.
3. In the Select a Project Template window, select Empty Activity and
click Next.
4. In the Configure your project window, complete the following:
• Enter "My First App" in the Name field.
• Enter "com.example.myfirstapp" in the Package name field.
• If you'd like to place the project in a different folder, change
its Save location.
• Select either Java or Kotlin from the Language drop-down menu.
• Select the lowest version of Android your app will support in
the Minimum SDK field.
• If your app will require legacy library support, mark the Use legacy
android.support libraries checkbox.
• Leave the other options as they are.
5. Click Finish.

After some processing time, the Android Studio main window appears.
6) first version of android?
> The very first version of Android was called as Android 1.0, which was
also known as Android Alpha.

7)Any 5 versions of android

> Alpha. Beta. Cupcake, Donut, Éclair, froyo, gingerbread, honeycomb,


ice cream sandwich, jelly bean, KitKat, lollipop, marshmallow, nougat,
Oreo, pie, android 10, android 11, android 11

8) Latest version of android


> Android 12

9) Purpose of xml file in android studio?


> This XML file defines the layout for the activity's user interface (UI).

10) purpose of android manifest file?


> The manifest file describes essential information about your app to the
Android build tools, the Android operating system, and Google Play.
The app's package name. The components of the app, the permissions that
the app needs in order to access protected parts of the system or other
apps. The hardware and software feature the app requires,

11) which is the root tag in android manifest file?


> <manifest> tag is the root tag of android manifest file.

12) How to create manifest file in android studio?


>
13) how to create xml file in android studio?
1. > Click the target app module in the Project window (while in either
the Android or Project view), and then select File > New > Android
resource file.

2. Fill in the details in the dialog:


• File name: Type the name for the XML file (does not require
the .xml suffix).
• Resource type: Select the type of resource you want to create.
• Root element: If applicable, select the root XML element for the file.
Some resource types support only one type of root element, so
depending on the type selected above, this might not be editable.
• Source set: Select the source set where you want to save the file.
• Directory name: The directory must be named in a way that's specific
to the resource type and configuration qualifiers. So you should not edit
this unless you want to add configuration qualifiers to the directory
name by hand (see Available qualifiers instead).
• Available qualifiers: Instead of typing configuration qualifiers for your
layout directory, you can add them by clicking a qualifier from the list

on the left, and then clicking Add .


3. Once you've added all the qualifiers you want, click OK.
14) which function link the java file with xml file?
> setContentView

15) base classes in android


> 1. Activity class: Activity class takes care of creating a window for you
in which you can place your UI with setContentView(View)
2. dialogue class: The Dialog class is the base class for dialogs,
3. fragment class: A Fragment represents a reusable portion of your app's
UI. A fragment defines and manages its own layout, has its own lifecycle,
and can handle its own input events.

16) steps for creating AVD (android virtual device)


> An Android Virtual Device (AVD) is a configuration that defines the
characteristics of an Android phone, tablet, Wear OS, Android TV, or
Automotive OS device that you want to simulate in the Android Emulator.
The AVD Manager is an interface you can launch from Android Studio
that helps you create and manage AVDs.

Step 1: Firstly, Select Tools > Android > AVD Manager > Click the AVD Manager icon in
the toolbar. Another way to open the AVD Manager directly by the AVD icon in the
Tool bar.
Step 2: Android Virtual Device Manager will be opened. After that Click on Create
Virtual Device.

Step 3: After that choose the Category, phone size and choose the pixels according to
your requirement. After this click on Next button.
Important Note: Choose the pixels resolution according to your requirements as it will
take huge RAM in large pixels resolution device. If your computer has low RAM then
prefer to choose less resolution device.

Step 4: After that choose the SDK Version and Click on Next button. If you have
various SDK Versions like Kitkat, Lolipop and Marshmallow etc in your SDK then you
can select one of them. Here we have only Marshmallow SDK Version. So, we can go
with the Marshmallow SDK Version. Click on the next.
Step 5: After that Enter the AVD Name in Android Virtual Device and Click on Finish
button. Here you can do customization to AVD which you are creating as per your
requirement.

Click Finish and new AVD is created.

Step 6: Now again open AVD manager and you will see your newely created AVD
(Android Virtual Device) is added in the list. Here click to Start the Virtual Device as
shown in figure below.
Step 7: After that your AVD will start in Emulator. Now you can run your App in this
AVD.

17) which is the first function that invokes when an activity starts?
> onCreate() is the first function that invokes when an activity starts

18) what is the meaning of super in terms of java?


> The super keyword refers to superclass (parent) objects. It is used to call
superclass methods, and to access the superclass constructor. The most
common use of the super keyword is to eliminate the confusion between
superclasses and subclasses that have methods with the same name.

19) Meaning of <receiver> in android studio?


> A broadcast is simply a message wrapped inside of an Intent object. A
broadcast can either be implicit or explicit.
An implicit broadcast is one that does not target your application
specifically so it is not exclusive to your application.
An explicit broadcast is one that is targeted specifically for your
application on a component that is known in advance.
There are two ways to declare a receiver:

1. By declaring one in your AndroidManifest.xml file with the


<receiver> tag (also called static)

2. You will notice that the broadcast receiver declared above has a
property of exported=”true”. This attribute tells the receiver that
it can receive broadcasts from outside the scope of the
application.

20) Meanings of:


> 1. Background: to set background color for android layout
2. gravity: android:gravity is used by the parent layout to tell the child
views how they should be placed inside it.
3. weight: Layout Weight in Android is the priority level of space that a
child view occupies in a linear layout.

21) difference between dp(density pixel) & sp(scalable pixel)


> To preserve the visible size of your UI on screens with different
densities, you must design your UI using density-independent pixels (dp)
as your unit of measurement. ... The sp unit is the same size as dp, by
default, but it resizes based on the user's preferred text size.

22) meaning of Log.d and package used for it


> Use this for debugging purposes. If you want to print out a bunch of
messages so you can log the exact flow of your program, use this. If you
want to keep a log of variable values, use this.
Package: util.Log

23) how to create fragment file in java?


> A Fragment represents a reusable portion of your app's UI. A fragment
defines and manages its own layout, has its own lifecycle, and can handle
its own input events. Fragments cannot live on their own--they must
be hosted by an activity or another fragment.

24) How to create java class file in android studio?


> Step 1: Go to Android Studio and open the project in Android mode
as shown in the below image.
Step 2: Now go to the app > java > your package name > right-click
> New > Java Class as shown in the below image.

Step 3: After completing step 2 a pop-up screen will arise like below.
Here enter your class name and choose Class and click
the Enter button.

After completing the above steps successfully you can find your Java
class here. Go to the app > java > your package name >
GeeksforGeeks.java. And you can write your own Java code here.
25) how to change layout in android studio?

> You can convert a view to another kind of view, and you can convert a
layout to another kind of layout.
1. Click the Design button in the top-right corner of the editor window.
2. In the Component Tree, right-click the view or layout, and then
click Convert view....
3. In the dialog that appears, choose the new type of view or layout,
and then click Apply.

26) any two listeners


> OnClickListener()
This is called when the user either clicks or touches or focuses upon any
widget like button, text, image etc. You will use onClick() event handler to
handle such event.
OnLongClickListener()
This is called when the user either clicks or touches or focuses upon any
widget like button, text, image etc. for one or more seconds. You will use
onLongClick() event handler to handle such event.
OnFocusChangeListener()
This is called when the widget looses its focus ie. user goes away from the
view item. You will use onFocusChange() event handler to handle such
event.
OnTouchListener()
This is called when the user presses the key, releases the key, or any
movement gesture on the screen. You will use onTouch() event handler to
handle such event.
OnMenuItemClickListener()
This is called when the user selects a menu item. You will use
onMenuItemClick() event handler to handle such event.
27) findViewById() is used for
> View is a class where all the widgets are defined.

R.id.myName specifies a view whose ID name is called myName

R is a Class that contains the ID's of all the Views

findViewById is the method that finds the View by the ID it is given.

28) base class of UI component?


> The basic building block for user interface is a View object which is
created from the View class and occupies a rectangular area on the screen
and is responsible for drawing and event handling. View is the base class
for widgets, which are used to create interactive UI components like
buttons, text fields, etc

29) meaning of cursor in android studio


> Cursor is the Interface which represents a 2 dimensional table of any
database. When you try to retrieve some data using SELECT statement,
then the database will first create a CURSOR object and return its
reference to you.

The pointer of this returned reference is pointing to the 0th location which
is otherwise called as before first location of the Cursor, so when you
want to retrive data from the cursor, you have to first move to the first
record so we have to use moveToFirst

When you invokes moveToFirst() method on the Cursor, it takes the


cursor pointer to the first location. Now you can access the data present in
the first record
30) different types of project templet
> basic activity

This template creates a simple app with an app bar and a floating action
button. It acts as a starting point for your project by providing commonly
used UI components.

Bottom Navigation Activity

This template provides a standard bottom navigation bar for an activity to


make it easy for users to explore and switch between top-level views in a
single tap. Use this template when your application has three to five top-
level destinations. For more information, see the Bottom Navigation
Component design guidelines.
Empty Activity

This template creates an empty activity and a single layout file with
sample text content. It allows you to start from scratch when building your
app module or activity.

Fullscreen Activity

This template creates an app that alternates between a primary fullscreen


view and a view with standard user interface (UI) controls. The fullscreen
view is the default and a user can activate the standard view by touching
the device screen.
Login Activity

This template creates a standard login screen. The user interface includes
email and password fields and a sign-in button. It is more commonly used
as an activity template than as an app module template.

Primary/Detail Flow (Renamed and updated in 4.2 Canary 8)

This template creates an app that has both an item list display and a
display for the details of an individual item. Clicking on an item on the list
screen opens a screen with the item’s details. The layout of the two
displays depends on the device that is running the app.
This template also provides API stubs for handling certain mouse and
keyboard inputs such as right-click actions on the list items as well as
common keyboard shortcuts.
Navigation Drawer Activity

This template creates a Basic Activity with a navigation drawer menu.


The navigation bar expands from the left or right side of your app and
appears in addition to the regular app bar.

Scrolling Activity

This template creates an app with a collapsing toolbar and a scrolling view
for long text content. As you scroll down the page, the toolbar, which can
serve as a header, automatically condenses, and the floating action button
disappears.
Settings Activity

This template creates an activity that displays user preferences or


settings for an app. It extends the PreferenceActivity class and is more
commonly used as an activity template than as an app module template.

Tabbed Activity

This template creates an app with multiple sections, swiping navigation,


and an app bar. The sections are defined as fragments between which you
can swipe left and right to navigate.
31) meaning of string buffer
> StringBuffer class is used to create mutable string and it is thread safe.
A string buffer is like a String, but can be modified. At any point in time it
contains some particular sequence of characters, but the length and content
of the sequence can be changed through certain method calls.
For example, if z refers to a string buffer object whose current contents
are "start", then the method call z.append("le") would cause the string
buffer to contain "startle", whereas z.insert(4, "le") would alter the string
buffer to contain "starlet".

32) how to create menu folder

> Adding Menu Resource Directory (res/menu)


Step 1: Open your project and right click on res, then click “New”, then “Android
resource directory”,

Add Android resource directory:


Step 2:
After that change the resource type to “menu” in the dropdown menu and then click
“OK”.

Change the resource type to menu:

Step 3:
Now you can see a new Android Resource Directory “menu” gets created,
Menu directory added:
Adding menu file in Menu Resource Directory

(res/menu/menu_main.xml)
Step 1: To create menu file in menu folder, right click on “menu” directory -
> “New” -> “Menu resource file“,
Add menu resource file:

Step 2: Give the file name, menu_main.xml -> click Ok,


Naming menu resource file to “menu_main.xml
Step 3: Now, you can see the directory structure, that shows the new file,
“menu_main.xml” in “menu” directory.
Menu Directory Structure:

You might also like