Documente Academic
Documente Profesional
Documente Cultură
Android is the World’s most popular Operating System owned by Google for smartphones and
tablet. The first beta version of the Android SDK was released by Google in 2007. However, the
first commercial version was released in 2008 and the name was given Android 1.0.
The latest release of Android is Android ‘P’ i.e. version 10. Android 10 launched on September 3,
Android is an Open Source mobile OS for smartphones and tablet. It is used widely on
smartphones. Android has Widgets to get information at a glance, you definitely don’t want an
application to be click and load. For that, Android comes with Widgets, to display weather,
Google search with voice-based features came with the initial release of Android. Just “OK
Google”. Voice Access feature introduced in 2018 for accessibility i.e. allowing users to control
Easily move to another task while working on a task in Android. You can run more than one
application at once.
The latest mobile screens have a support with the introduction of Android 9. The DisplayCutout
class allow you to get the location and shape of the areas where content shouldn’t be made
visible.
In the recent Android release, you can now display images in Messaging Notifications on phones.
For displaying message with images, use the setData() method. It also came with the
Now, you can also work with machine learning on Android. Neural Networks API introduced in
Android 8.1 to quicken on-device machine learning on Android. The API enhanced in Android 9.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 2 – What are the core building blocks of Android?
The core building blocks of Android include activities, views, intents, fragments, service,
Activity
Android program begins with an Activity. It is a single screen, wherein you can place components
or widgets.
View
View objects are User Interface elements in Android that responds to the user’s actions.
Content Providers
ContentProvider class. The data can be stored in files, database, network, etc.
Service
Service perform long-running operations. It is a background process, therefore the operations run
in the background.
Intent
message between activities, content providers, etc. The startActivity is used with Intent to launch
an Activity.
The Intents are used for Starting a service, launching an activity, displaying list of contacts, phone
AndroidManifest.xml
AndroidManifest.xml has key information about the Android app and it is the root of the project
source set.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
The Android Virtual Device (AVD) provides a device specific environment to install and run
Android apps. The environment defines the features of Android Tablet, Phone, Android TV, etc.
The same is displayed in the Emulator, for example, Google Nexus set as AVD. Simulate the
The “AVD Manager” is a part of the Android Studio that assists in creating and managing the
Android is an OS owned by Google for smartphones and tablet. The first beta version of the
Android SDK was released by Google in 2007. However, the first commercial version was
Using the built-in infrared transmitter, you can easily use phone or tablet as remote control.
Widget
To get information at a glance, you definitely don’t want an app to be click and load. For that,
Android comes with Widgets, to display weather, calendar, live news, score updates on the right –
Google search with voice-based features came with the initial release of Android. Just “OK
Google”.
Voice Access feature introduced in 2018 for accessibility i.e. allowing users to control your device
Multi-tasking
Easily move to another task while working on a task. You can run more than one application at
once.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Alternate Keyboards
Android supports multiple keyboards. These keyboards you can easily install like SwiftKey.
SwiftKey’s artificial intelligence predict the next word the user intends to type.
Multi-touch gestures
A multi-touch gesture features works great in Android. This gesture occurs when multiple finger
touch the screen at the same time. Some of the touch events generated by Android are:
ACTION_DOWN for the 1st pointer touching the screen, ACTION_UP when the last pointer leaves
the screen.
Storage
Android has built-in SQLite database implementation. SQLite is an open source relational
database.
Android 10 is the latest version of Android, released September 3 rd, 2019. Following are some of
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 5 – What are the disadvantages of Android?
Android is an open source mobile Operating System. The first beta version of the Android SDK
was released by Google in 2007. However, the first commercial version was released in 2008 and
Multiple Applications
When multiple applications are open in Android, then the rate of battery consumption is high.
Some apps on the Play Store aren’t compatible with all the functionalities. This may lead to app
crashes. A new Android release on your phone may lead to the functionalities of some of the apps
to stop working, since these apps were compatible with previous versions.
Malware
Mobile-specific malware are being designed to attack smartphones and vulnerabilities are
emerging. This leads to data safety issues for some users whose mobile get attacked by these
Malwares.
Fragmentation
Not all Android phones and apps adapt to the new version of the OS. This is due to the reason
With Toast in Android, user can display a notification for a short period time.
Note: Toast doesn’t block the user’s interaction with the app. Current activity also remains visible.
An example would be on click of a button to begin an Android game, a Toast saying “Loading….”
Visible below.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
The difference between a Notification and Toast is that with a Notification you can get a user
1 Toast.makeText(getApplicationContext(),"Loading…!",Toast.LENGTH_SHORT).show();
3
5 myToast.show();
Msg) methods.
Application Context: We use getApplicationContext, which returns the context of the single, global
Application object of the current process.
Toast_Duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG
Msg: The message to be displayed in the Toast.
If you do not want to position the toast in the bottom (centered horizontally), then use the
setGravity(int, int, int) method to change the position.A standard toast notification appears near the
bottom of the screen, centered horizontally. You can change this position with the setGravity(int,
Gravity constant
x-position offset
y-position offset
1 toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0);
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 7 – Why do we use Emulator within Android?
If you want to test your application on a device, without physically having it, then use the Emulator.
You can select the version on which you want to test your app using it.
With Emulator, you can see easily the Android version and API levels you want for your Android
Virtual Device. This AVD tests your app without the need of a physical device.
With an Emulator, you can easily send phone calls and SMS without needing an Android phone.
Emulate Battery
The emulator allows a developer to check the effect of background apps on battery so that an app
Transfer Files
Using DDMS in Android Studio, easily transfer files into the emulator for testing purposes.
Emulate location
With Android Emulator, you can emulate the location as well. Get the Latitude, Longitude, Altitude,
etc. for any location without the need of a physical device to test.
Emulate Fingerprint
Nowadays, fingerprint scanner can be found in Android phone. You can also emulate that using
the Emulator.
Android program begins with an Activity. It is a single screen, wherein you can place components
or widgets.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
The Android lifecycle begins with the onCreate() method:
During the Android Activity Life Cycle, the following callback methods are used:
onCreate()
The callback method onCreate() is called when the activity first gets creates.
onStart()
The callback method onStart() is called when the activity is visible to the user.
onResume()
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
The callback method onResume() is called after onRestoreInstanceState(), onRestart(), or
onPause()
The callback method onPause() is called when an activity is going into the background and is
paused.
onStop()
The callback method onStop() is called when the activity is no longer visible to the user.
onRestart()
The callback method onRestart() is called when an activity restarts after stopping.
onDestroy()
AndroidManifest.xml has key information about the Android app and it is the root of the project
source set.
Package Name
The AndroidManifest.xml would definitely have the app’s package name. This is visible at the top:
1 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
3 package="com.studyopedia.exampleapplication">
Activities
The Manifest file defines all the activities, services, broadcast receivers, etc.
1 <activity android:name=".MainActivity">
2 <intent-filter>
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
3 <action android:name="android.intent.action.MAIN" />
4
6 </intent-filter>
7 </activity>
1 <activity android:name=".Numbers_Intro"></activity>
2 <activity android:name=".NumbersLearn"></activity>
3 <activity android:name=".NumbersWrite"></activity>
4
5 <activity android:name=".Shapes_Intro"></activity>
6 <activity android:name=".ShapesLearn"></activity>
7 <activity android:name=".ShapesWrite"></activity>
Permissions
The Manifest file also has information about the permissions you may have set to access different
Intents
The <Intent-Filter> elements are included in the Manifest file to specify the type of intents that an
An example:
1 <activity android:name=".MainActivity">
2 <intent-filter>
5 </intent-filter>
6 </activity>
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 10 – What is an ADB in Android?
ADB is Android Debug Bridge, which is a command-line tool to communicate with a device. You
get access to a UNIX shell with a variety of commands using the ADB command. Installing and
debugging apps also comes under ADB. You can also use adb with a device connected over USB.
Client: Client runs on the development machine. Invoke it using the abd command.
Daemon: It runs as a background process.
Server: The server manages communication between the client and the daemon.
The concept of Fragments introduced in Android 3.0 (API level 11), for dynamic designs to be
implemented primarily on tablets (large screens).
You can add more than one fragment in an activity. Create fragments by extending Fragment
class. Fragments can also be considered as a “sub activity” that can be reused in different
activities. We can add or remove even when the activity is running. A fragment has its own
lifecycle.
To create a fragment, extend the Fragment. Use the onCreateView() callback method to define the
layout.
Before fragments, only a single activity was allowed on the screen at a time. This was a limitation
for developers since they were unable to customize the screen i.e. dividing the screen to give
control the separately according to the need of the clients. It removed the limitation of having a
A subclass of fragment is to be created to create a new Fragment. The callback methods in the
onAttach(Activity)
Called only once when it is attached with activity.
onCreate(Bundle)
Initializes the fragment.
onCreateView(LayoutInflater, ViewGroup, Bundle)
Creates and returns view hierarchy. Null is returned if UI is not provided by the fragment.
onActivityCreated(Bundle)
It is invoked after the completion of onCreate() method. Now, view can be accessed with the findViewById()
method.
onViewStateRestored(Bundle)
It provides information to the fragment that all the saved state of fragment view hierarchy has been
restored.
onStart()
Called when the fragment is visible.
onResume()
Fragment is active.
onPause()
Called when fragment is no longer interactive i.e. user is leaving the fragment.
onStop()
Called when fragment is no longer visible.
onDestroyView()
Allows the fragment to clean up resources.
onDestroy()
Allows the fragment to do final clean-up of fragment state.
onDetach()
Called immediately prior to the fragment no longer being associated with its activity.
The Explicit Intent allows users to connect one activity to another. It is for an application to launch
various internal activities.
The following is an example that connects the current activity to next activity Demo.class:
We have an activity “MainActivity.java”. In that, we have a button. On click of button, we will reach
reach the next activity i.e. “DemoActivity. Java” using Explicit Intent.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
1 public class MainActivity extends AppCompatActivity {
2
3 EditText eText;
4 Button btnSubmit;
5 String name;
6
7 @Override
9
10 super.onCreate(savedInstanceState);
11 setContentView(R.layout.activity_main);
12
15
17
18 @Override
21 startActivity(ob);
22 }
23 });
24 }
25 }
The Implicit Intent define the action to be performed for different activities. These Intents do not
2 i.setAction(Intent.ACTION_SEND);
Let us see an example of Implicit Intent wherein we will display a web page:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
activity_main.xml
2 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"
7 tools:context="demo.com.studyopediaimplicitintent.MainActivity">
8
9 <EditText
10 android:id="@+id/editText"
11 android:layout_width="wrap_content"
12 android:layout_height="wrap_content"
13 android:layout_marginEnd="10dp"
14 android:layout_marginStart="10dp"
15 android:layout_marginTop="65dp"
16 android:ems="10"
17 app:layout_constraintEnd_toEndOf="parent"
18 app:layout_constraintHorizontal_bias="0.575"
19 app:layout_constraintStart_toStartOf="parent"
21
22 <Button
23 android:id="@+id/button"
24 android:layout_width="wrap_content"
25 android:layout_height="wrap_content"
26 android:layout_marginRight="10dp"
27 android:layout_marginLeft="150dp"
28 android:layout_marginTop="180dp"
29 android:text="URL"
30 app:layout_constraintEnd_toEndOf="parent"
31 app:layout_constraintHorizontal_bias="0.0"
32 app:layout_constraintStart_toStartOf="parent"
34
35 </android.support.constraint.ConstraintLayout>
MainActivity.java
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
1 package demo.com.studyopediaimplicitintent;
2
3 import android.content.Intent;
4 import android.net.Uri;
5 import android.support.v7.app.AppCompatActivity;
6 import android.os.Bundle;
7 import android.view.View;
8 import android.widget.Button;
9 import android.widget.EditText;
10
12
15
16 @Override
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.activity_main);
22
24
25 @Override
29 startActivity(i);
30 }
31 });
32 }
33 }
On running the above code, you can see an EditText wherein you can add the URL. On clicking
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 15 – What were the features introduced in Android 9 (Pi)?
Cutout Support
The latest mobile screens have a support with the introduction if Android 9. The DisplayCutout
class allow you to get the location and shape of the areas where content shouldn’t be made
visible.
Images Support
With Android 9, you can now display images in Messaging Notifications on phones. For displaying
Decoding Images
Android 9 came with the ImageDecoder class to provide a modernized approach for decoding
images.
Animation
The AnimatedImageDrawable class introduced in Android 9 and allow developers to draw and
HDR-enabled Movies
Now, Android has built-in support for High Dynamic Range (HDR) VP9 Profile 2. This helps to
deliver HDR-enabled movies from YouTube, Play Movies, etc on HDR-capable devices.
Neural Networks API introduced in Android 8.1 to quicken on-device machine learning on Android.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 16 – What are the Dialog Boxes supported in Android?
If you want to display a small window to the users to take a decision or add information, then use
the dialogs in Android. The Dialog class is provided by Android to create a dialog box. The
AlertDialog
It is a dialog that asks users to take decision between yes or no in response of any particular
DatePickerDialog
TimePickerDialog
1 dialogBuilder.setPositiveButton(CharSequence text,
2
3 DialogInterface.OnClickListener listener)
2
3 DialogInterface.OnClickListener listener)
2 dialog.show();
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 17 – What is an AVD?
The Android Virtual Device (AVD) provides a device specific environment to install and run
Android apps. The environment defines the features of Android Tablet, Phone, Android TV, etc.
The same is displayed in the Emulator, for example, Google Nexus set as AVD. Simulate the
The “AVD Manager” is a part of the Android Studio that assists in creating and managing the
Android Virtual Devices. Follow the below steps to open AVD Manager and create an AVD:
Step 2: Click “Create Virtual Device” as shown above to create a new virtual device.
Step 3: You will reach the “Select Hardware and Device Definitions” section for the AVD.
The keyboard shortcuts are quite useful for any IDE whether it’s Eclipse or Android Studio. Let us
see some of the useful keyboard shortcuts that could help developers in using the IDE:
The view group is the base class for layouts and views containers. These layouts include the UI
A ViewGroup is a view under which the layouts and views are set. It defines the
layouts parameters.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Here are some of the methods of the ViewGroup class beneficial while creating a view:
Show entries
Search:
addView(View child, int width, int The method a child view with ViewGroup's default layout parameters
height) and the specified width and height.
clearChildFocus(View child) The method is called when a child of this parent is giving up focus
clearDisappearingChildren() The method removes any pending animations for removed views.
Showing 1 to 10 of 17 entries
PreviousNext
A Drawable is for the graphic to be drawn on the screen. You can view the Drawable folders in the
1 res/drawable
Bitmap File
Nine-Patch File
A PNG file with stretchable regions to allow image resizing based on content i.e. 9.png.
Layer List
A Drawable that manages an array of other Drawables. These are drawn in array order, so the
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
State List
References different bitmap graphics for different states, An example can be to use a different
Level List
Defines a drawable that manages a number of alternate Drawables, each assigned a maximum
Transition Drawable
Defines a drawable that can cross-fade between two drawable resources. It is an XML file.
Inset Drawable
An XML file that defines a drawable that insets another drawable by a specified distance. This is
useful when a View needs a background drawable that is smaller than the View’s actual bounds.
Clip Drawable
A drawable that clips another Drawable based on this Drawable’s current level value. It is an XML
file.
Scale Drawable
A drawable that changes the size of another Drawable based on its current level value. It is an
XML file.
Shape Drawable
View
View objects are User Interface elements in Android that responds to the user’s actions.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
ViewGroup
The view group is the base class for layouts and views containers. These layouts include the UI
The subclass of View is ViewGroup. ViewGroup is an object that holds other View
A ViewGroup is a view under which the layouts and views are set. It defines the
layouts parameters.
An example to state the difference further is that LinearLayout has Button, and other Layouts.
Linear Layout
Relative Layout
Linear Layout
The Linear Layout arranges views horizontally or vertically. For this, set the following under linear
layout:
1 android:orientation="horizontal"
1 android:orientation="vertical"
The following are some of the useful methods that helps in working with LinearLayout:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Relative Layout
Specify the position of child views relative to each other or parent. The following are some of the
constants of RelativeLayout:
Margins
Margin is outside the View. View here can be a EditText, Button, etc.
To add right margin i.e. extra space on the right side of the view, use the following attribute:
1 android:layout_marginEnd = "50dp"
To add left margin i.e. extra space on the left side of the view, use the following attribute:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
1 android:layout_marginStart = "50dp"
To add top margin i.e. extra space on the top side of the view, use the following attribute:
1 android:layout_marginTop = “50dp"
To add bottom margin i.e. extra space on the bottom side of the view, use the following attribute:
1 android:layout_marginBottom = “50dp"
Ques 24 – Which Android Layout arranges its children into rows and
columns?
The TableLayout allow its children to be arrange into rows and columns. The layout will have a
1 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="fill_parent"
3 android:layout_height="fill_parent">
4
5 <TableRow
6 android:layout_width="fill_parent"
7 android:layout_height="fill_parent">
8
9 <TextView
10 ...
11 />
12 <TextView
13 ...
14 />
15
16 </TableRow>
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
17 <TableRow>
18 <TextView
19 ...
20 />
21 <EditText
22 ...
23 />
24 </TableRow>
25 <TableRow
26 android:layout_width="fill_parent"
27 android:layout_height="fill_parent">
28
29 <Button
30 ...
31 />
32
33 </TableRow>
34 </TableLayout>
Android is an Open Source mobile OS for smartphones and tablet. It is used widely on
smartphones. Android has Widgets to get information at a glance, you definitely don’t want an
application to be click and load. For that, Android comes with Widgets, to display weather,
Google search with voice-based features came with the initial release of Android. Just “OK
Google”. Voice Access feature introduced in 2018 for accessibility i.e. allowing users to control
Easily move to another task while working on a task in Android. You can run more than one
application at once.
The latest mobile screens have a support with the introduction of Android 9. The DisplayCutout
class allow you to get the location and shape of the areas where content shouldn’t be made
visible.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
In the recent Android release, you can now display images in Messaging Notifications on phones.
For displaying message with images, use the setData() method. It also came with the
Now, you can also work with machine learning on Android. Neural Networks API introduced in
Android 8.1 to quicken on-device machine learning on Android. The API enhanced in Android 9.
Set custom build configurations in Android with Gradle. To generate an apk, the role of Gradle is
quite important. Android Gradle gathers the source files and converts them into a file, which we
call apk. The apk is the file which is used to upload an Android app on the Google Play Store.
Whenever you create an Android app, on the left, you can see the following “Gradle Scripts”
section. Under that you can see two Gradle i.e. Gradle (Project) and Gradle (Module):
The build.gradle (project) define the build configuration applies to the modules of the project. As
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
In this, the SDK versions are declared. It includes other blocks as well as shown below:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 27 – When and why Fragments were introduced in Android?
The concept of Fragments introduced in Android 3.0 (API level 11), for dynamic designs to be
Before fragments, only a single activity was allowed on the screen at a time. This was a limitation
for developers since they were unable to customize the screen i.e. dividing the screen to give
Fragments came to the rescue and now you can easily divide a screen in multiple fragments and
control the separately according to the need of the clients. It removed the limitation of having a
You can add more than one fragment in an activity. Create fragments by extending Fragment
class. Fragments can also be considered as a “sub activity” that can be reused in different
activities. We can add or remove even when the activity is running. A fragment has its own
lifecycle.
XML defines a rule for encoding documents. In Android, we can easily parse XML data and use
DOM
SAX, and
XMLPullParser
Analyzing
Work on the XML and find out the fields from which you want the parser to extract data.
Instantiation
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
A parser is initialized with InputStream as input. The parsing process begins with a call to
nextTag() and invokes the readFeed() method. The parser is instantiated to extract and process
the data.
Processing
The processing of feed is done using the readFeed() method. It returns a list of entries extracted
PendingIntent is a reference to a token. It is like telling the foreign application to execute some
predefined code and act on behalf of the application using the listed permissions of your
FLAG_CANCEL_CURRENT: Flag indicating that if the described PendingIntent already exists, the
current one should be canceled before generating a new one.
FLAG_IMMUTABLE: Flag indicating that the created PendingIntent should be immutable.
FLAG_NO_CREATE: Flag indicating that if the described PendingIntent does not already exist, then
simply return null instead of creating it.
FLAG_ONE_SHOT: Flag indicating that this PendingIntent can be used only once.
FLAG_UPDATE_CURRENT: Flag indicating that if the described PendingIntent already exists, then
keep it but replace its extra data with what is in this new Intent.
Gravity in Android sets how an object is placed in a container. The android:gravity attribute places
an object in a large container. The Gravity sets the gravity of the content of the View (Button,
To place the object property, the following are the constant provided by Android for Gravity:
BOTTOM: Push object to the bottom of its container, not changing its size.
CENTER: Place the object in the center of its container in both the vertical and horizontal axis, not
changing its size.
CENTER_HORIZONTAL: Place object in the horizontal center of its container, not changing its size.
CENTER_VERTICAL: Place object in the vertical center of its container, not changing its size.
CLIP_HORIZONTAL: Flag to clip the edges of the object to its container along the horizontal axis.
CLIP_VERTICAL: Flag to clip the edges of the object to its container along the vertical axis.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
DISPLAY_CLIP_HORIZONTAL: Special constant to enable clipping to an overall display along the
horizontal dimension.
DISPLAY_CLIP_VERTICAL: Special constant to enable clipping to an overall display along the
vertical dimension.
END: Push object to x-axis position at the end of its container, not changing its size.
FILL: Grow the horizontal and vertical size of the object if needed so it completely fills its container.
FILL_HORIZONTAL: Grow the horizontal size of the object if needed so it completely fills its
container.
RIGHT: Push object to the right of its container, not changing its size.
START: Push object to x-axis position at the start of its container, not changing its size.
TOP: Push object to the top of its container, not changing its size.
1 <LinearLayout
2 android:layout_width="match_parent"
3 android:layout_height="match_parent"
4 android:gravity="center_vertical"
6 <EditText
7 android:id="@+id/edittext"
8 android:layout_width="match_parent"
9 android:layout_height="wrap_content"
10 android:layout_margin="20dp"
12
14 </EditText>
15 </LinearLayout>
The MediaRecorder class is used in Android to record audio or video. Before implementing the
1 myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
1 myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
The above set output formats can be any of the following based on what user needs:
1 myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
The getAllNetworkInfo() method is used in Android to get information of all the networks. Here’s
To control ringer volume in Android app, you can use the AudioManager class. The ringer profile
includes the modes silent, vibrate, etc. modes. The AudioManager class allow you to work with
these controls.
Mode Description
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Mode Description
Let us see how to work with the modes and set the ringer volume:
2 myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
Step2: Now, set the ringer profile. For this the setRingerMode() method is used.
1 audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1 audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
1 audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Ques 34 – What are the key Java-Based libraries for Android App
Development?
The following are the libraries available for Android app development:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 35 – What are the Application Components of an Android
Application?
Activity
Android program begins with an Activity. It is a single screen, wherein you can place components
or widgets.
View
View objects are User Interface elements in Android that responds to the user’s actions.
Intent
message between activities, content providers, etc. The startActivity is used with Intent to launch
an Activity.
The Intents are used for Starting a service, launching an activity, displaying list of contacts, phone
AndroidManifest.xml
AndroidManifest.xml has key information about the Android app and it is the root of the project
source set.
Layouts
Layouts sets the appearance of the view. Specify the position of child views relative to each other
or parent with Relative Layout. However, the Linear Layout arranges views horizontally or
vertically.
Content Providers
ContentProvider class. The data can be stored in files, database, network, etc.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Service
Service perform long-running operations. It is a background process, therefore the operations run
in the background.
Within Android, you can test your application. The Test Tools consider that the Android Project is
The UI/Application Exerciser Monkey is a command-line tool that sends pseudo-random streams
of user events. These events can be touch, gesture, etc. It runs of the emulator or device.
JUnit
The JUnit TestCase class us to be used to perform unit testing on a class. This class shouldn’t call
Android APIs.
The base class for AndroidTestCase is TestCase, that can be used to test Android-dependent
objects.
For UI Testing, the UI Automator Testing Framework is used. It is used for cross-app functional
UI testing. To perform operations on the target device, this test framework is used.
UI Automator viewer
The uiautomatorviewer tool provides a GUI to scan and analyze the UI components. These
components are shown on the Android device and use this tool to view the UI components
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 37 – What is the process of drag and drop in Android?
With Android, it’s not a tedious task to drag and drop in a View to another. For example, you can
Step1: Begins when a user makes a gesture and starts dragging an item. Application calls the
startDrag() method. The data to be dragged is included as a parameter. The system responds by
calling back to the application. This gets a drag shadow and the same is displayed on the device.
Step2: The drag continues and the system sends ACTION_DRAG_ENTERED action. This is
Step3: User releases the dragged item at the place of a View where the destination is. System
sends the View object’s listener a drag event with action type ACTION_DROP.
Step4: System now sends out a drag event with action type ACTION_DRAG_ENDED. This is to
To launch an existing camera application i.e. the camera on your Android device, use the
1 startActivityForResult(i,0);
The Intents are also available for other applications like launch camera in video mode, or you can
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 39 – Which API is provided by Android to manage WiFi
connectivity?
The WifiManager API allows users to manage WiFi connectivity. Using the API, the following
1 button.setOnClickListener(new OnClickListener(){
2
4
6 w.setWifiEnabled(true);
7 }
8 });
As discussed above, the actions that can performed by the WiFiManager API. For this, various
To create a RadioButton in Android, you can always just drag and drop from the Android Studio
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Let’s say we are creating 4 dynamic Radio Buttons. For that, since we are not using the
activity_main.xml
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"
7 android:paddingBottom="@dimen/activity_vertical_margin"
8 android:paddingLeft="@dimen/activity_horizontal_margin"
9 android:paddingRight="@dimen/activity_horizontal_margin"
10 android:paddingTop="@dimen/activity_vertical_margin"
11 android:id="@+id/relLayout"
12 tools:context="com.studyopedia.example.dynamicradio.MainActivity">
13 </RelativeLayout>
MainActivity.java
1 package com.studyopedia.example.dynamicradio;
2
3 import android.support.v7.app.AppCompatActivity;
4 import android.os.Bundle;
5 import android.widget.RadioButton;
6 import android.widget.RadioGroup;
7 import android.widget.RelativeLayout;
8 import android.widget.RelativeLayout.LayoutParams;
9 import android.widget.Toast;
10
12
16
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
17 @Override
19
20 super.onCreate(savedInstanceState);
21 setContentView(R.layout.activity_main);
22
25
31
32 r1.setText("Football");
33 r2.setText("Tennis");
34 r3.setText("Golf");
35 r4.setText("Cricket");
36
37 radioGroup.addView(r1);
38 radioGroup.addView(r2);
39 radioGroup.addView(r3);
40 radioGroup.addView(r4);
41
42 radioGroup.setOrientation(RadioGroup.VERTICAL);
43
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
55 public void onCheckedChanged(RadioGroup group, int checkedId) {
57 Toast.makeText(getApplicationContext(),radioBtn.getText(),Toast.LENGTH_LONG).show();
58 }
59 });
60 }
61 }
When you will create an Android app, you would definitely need a storage area. You may also
To store data and read it in Android, the following options are available:
Internal Storage
With Android, you can save and read data from the device’s internal memory. It is the storage of
External Storage
If you want to read data or save to an external storage, then this is also possible. This external
Store data in key and value pair with Shared Preferences in Android. The data can be retrieved in
SQLite
SQLite is an opensource SQL database to store data to a text file on a device. Android has built-in
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 42 – What is Android Asset Packaging Tool?
Android Asset Packaging Tool is the base builder for Android applications. To compile and
package the resources of the app, the Android Studio use it.
The resources are compiled and parsed in a binary format. This format is optimized for the
Android.
Locate AAPT2
To locate Android Asset Packaging Tool in the Android Studio, you need to download Android
1 sdkmanager "build-tools;build-tools-version"
After downloading the Android SDK Build Tools, find the APPT2 at the following location:
1 android_sdk/build-tools/version/
1 NetworkInfo.State.CONNECTED
The following are the points that would help you in deciding when you should go for Fragments
A fragment is a part of an activity, which contributes with its own UI to that activity.
A fragment can be thought of as a sub-activity, whereas the complete screen with which user
interacts is called as “activity”.
An activity has multiple fragments.
Combine multiple fragments in a single activity to build a multi-pane UI.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
You can add or remove fragments in an activity while the activity is running.
An activity may contain 0 or multiple number of fragments based on the screen size.
A fragment is a reusable component in activities.
You can use a fragment in multiple activities.
Fragments can be used to populate Menus.
A fragment should always be part of activity. However, activity can exist without any fragment in it.
Fragments live inside activities.
Each activity can host many fragments.
Ques 45 – Can two Android applications share same Linux user ID and
share same VM?
Yes, two Android applications can share same Linux user ID and VM. A unique user ID is
Android assigns a unique user ID to each application. Set the same values for both the Android
Padding is within the View. For example, padding is inside a Button control. Padding is or the left,
top, right and bottom parts of the view. Here, view can be a Button, TextView, etc.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
An example here displays a Button View:
To add right padding i.e. the Button will shift to the left within the view, use the following attribute:
1 android:layout_paddingEnd = "50dp"
To add left padding i.e. the Button will shift to the right within the view, use the following attribute:
1 android:layout_paddingStart = "50dp"
To add top padding i.e. the Button will shift to the bottom within the view, use the following
attribute:
1 android:layout_paddingTop = "50dp"
To add bottom padding i.e. the Button will shift to the top within the view, use the following
attribute:
1 android:layout_paddingBottom = "50dp"
Use the Window class to access the menus, icon on the title bar, enable Action Control, color of
the window caption controls, etc. This is also used to hide the Title Bar.
To hide the Title Bar, use the following method and set it to “FEATURE_NO_TITLE”:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
1 requestWindowFeature(Window.FEATURE_NO_TITLE)
This is the constant for the “no title” feature that turns off the title at the top of the screen.
After that use the getSupportActionBar() method and hide() method to hide:
1 getSupportActionBar().hide();
Following is the Java code for what we discussed above to hide the Title Bar:
2
3 @Override
5
6 super.onCreate(savedInstanceState);
7 requestWindowFeature(Window.FEATURE_NO_TITLE);
8 getSupportActionBar().hide();
9 setContentView(R.layout.activity_main);
10 }
11 }
Encryption of data
The data in the Android app should be encrypted specially when the information is confidential and
personal.
Within Android, you can test your application. The Test Tools consider that the Android Project is
organized into test structure, test classes, test package, etc. Some tools are UI/Application
Accessibility
Set the description for Controls like tabs, button, sliders, etc. With that, do not forget to set the with
A best practice to follow while developing apps is to place your app icons in mipmap- because
they are used at resolutions different from the device’s current density. Avoid including it under the
drawable- folders.
Always try to avoid deep levels in layouts. Depp levels makes it difficult for the interface to work.
The simplest way to avoid it is using the correct ViewGroup. You need to prefer single view
hierarchy.
For protecting the privacy of Android smartphone and tablet users, a concept called Permissions
for Android apps is covered. The apps must request permissions for:
Add the <uses-permission> tag in the app manifest file. This permission would be visible for users
when that particular feature in the app is accessed. For example, for recording audio, immediately
Normal Permissions
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
If normal permissions are listed in its manifest, then the system automatically grants those
permissions to your app. This is because the permissions aren’t risky to the privacy of users or the
Dangerous Permissions
If dangerous permissions are listed in its manifest, then the user needs to explicitly agree for
granting the permissions. This is because the permissions are risky to the privacy of users or the
CAMERA CAMERA
MICROPHONE RECORD_AUDIO
To achieve this, you need to use the FrameLayout. You can add a single child or multiple child
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Let us see how you can create a FrameLayout in activity_main.xml:
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent">
5
6 <ImageView
7 android:src="@drawable/ic_launcher"
8 android:scaleType="fitCenter"
9 android:layout_height="200px"
10 android:layout_width="200px"/>
11
12 <TextView
13 android:text="Example"
14 android:textSize="20px"
15 android:layout_height="fill_parent"
16 android:layout_width="fill_parent"
17 android:gravity="center"/>
18
19 </FrameLayout>
ContentProvider class. The data can be stored in files, database, network, etc.
The Content Provider centralize content and allow different applications access it. Let us see how
Create a Content Provider class that extends the Content Provider base class.
Define content provider URI address to be used to access the content.
Create a database to store the content.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
You can use the SQLite database. The onCreate() handler of each of its Content Providers is called
on the main application thread when the application is launched.
Implement Content Provider queries for performing different database specific operations.
Register your Content Provider in the activity file using <provider> tag.
Here are the methods used while working with Content Provider:
Android Runtime (ART) is the managed runtime. It is used by applications on Android. ART and
Dalvik were created specifically for the Android project. Dalvik is the predecessor of ART and
optimized the virtual machine for memory, battery life and performance.
ARM executes the Dalvik Executable format and Dex bytecode specification. The dx tool gets all
the class files of your application and generates a single .dex file. It converts the Java class files in
.dex files.
Dalvik uses a just-in-time (JIT) compiler to compile code when you run an app. However, ART
uses an ahead-of-time (AOT) compiler and pre-compiles bytecode when the app is installed.
Note: Android removes the aging virtual machine and replaced it with ART in 2014.
ART has ahead-of-time (AOT) compilation to enhance app’s performance. At the time of
Debugging Options
ART has a number of debugging options. This includes, locks in stack traces, instances of a given
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
ART provides with the detailed report for runtime exceptions. The details included are for:
lang.ClassCastException
lang.ClassNotFoundException
lang.NullPointerException
lang.ArrayIndexOutOfBoundsException
lang.ArrayStoreException
The ART compacts the Garbage Collector to minimize background memory usage.
The Java API and virtual machine are designed for desktop, not have that much compatibility with
mobile devices. This is why a separate virtual machine is created for mobile devices, called Dalvik
virtual machine.
The bytecode is translated to Dalvik bytecode. It is optimized for low power handheld devices i.e.
mobile devices. In 2014, Dalvik was replaced by ART (Android Runtime). Android runtime (ART) is
the managed runtime. It is used by applications on Android. ART and Dalvik were created
specifically for the Android project. Dalvik is the predecessor of ART and optimized the virtual
ARM executes the Dalvik Executable format and Dex bytecode specification.
The dx tool gets all the class files of your application and generates a single .dex file. It converts
Dalvik uses a just-in-time (JIT) compiler to compile code when you run an app. However, ART
uses an ahead-of-time (AOT) compiler and pre-compiles bytecode when the app is installed.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 55 – What is a Widget in Android?
Android has Widgets to get information at a glance, you definitely don’t want an application to be
click and load. For that, Android comes with Widgets, to display weather, calendar, live news,
Users can move and resize the widgets. Let us learn about the types of Widgets in Android:
Information Widgets
To display information like clock, live score update, weather, etc., use the Information Widgets. To
Collection Widget
Control Widget
These are functions that can be operated from the home screen like music app, allowing users to
play and pause music without operating the actual music app.
To speed up Gradle build process in Android Studio, try the below given steps:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 58 – Why do we use Android Parceable?
Parcelable lets developers to serialize a class so its properties are easily transferred from one
Pickers is a component in Android that allows users to select date or time. This is possible since
The following are some of the methods of TimePicker that allows you to get the current time,
The following are some of the methods of DatePicker that allows you to get the current month,
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 61 – What is a Location Object in Android?
It represents a geographic location that has timestamp, latitude, longitude, etc. To get location
specific information with the Location Object, following are the methods:
To check Internet connection in Android, you need to use the ConnectivityManager class.
1 ConnectivityManager c = (ConnectivityManager)
2 this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
Ques 63 – What are the Java classes for using sensors in Android?
The Google Map API is used in Android to integrate Google Map in the Android app. You can
display any location on the map, show current location, search directions, etc. With the API, you
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
On a Map, you may have seen a lot of Markers. On every Marker, you see a text, for example, a
restaurant, monument, etc. Let us see how we can add a marker in an Android app. The
2
4
5 .position(Demo).title("MyRestaurant"));
1 gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
2 gMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
3 gMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
4 gMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
Following are the methods that allow you to customize the Google Map like adding a polygon on
To work with Database on Android, the most widely used Database in SQLite. It is an opensource
SQL database to store data to a text file on a device. Android has built-in SQLite database
implementation.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
The package “android.database.sqlite” has a lot of functions that allows you to manage the
Android database SQLIte. One of them is “openOrCreateDatabase()”. Here, the database name is
DemoDB:
1 SQLiteDatabase db = openOrCreateDatabase("DemoDB",MODE_PRIVATE,null);
To insert a data, you need the execSQL method() method. This works like the Create and Insert in
SQL:
Create
1 db.execSQL("CREATE TABLE IF NOT EXISTS EMPTABLE(empname VARCHAR,empdept VARCHAR, empzone);");
Insert
1 db.execSQL("INSERT INTO VALUES('Amit','IT', 'North' );");
Now, if you need to get the data from the database, the Cursor class include some methods. Let
us learn about these methods can the role they perform in getting the number of rows, columns,
Fragments can also be considered as a “sub activity” that can be reused in different activities. We
can add or remove even when the activity is running. A fragment has its own lifecycle. A fragment
is a reusable component in activities. You can use a fragment in multiple activities. Fragments can
be used to populate Menus. An activity may contain 0 or multiple number of fragments based on
ListFragment
DialogFragment
Single Frame Fragment
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
ListFragment
This fragment has a ListView view by default. Use it for displaying a list of items
DialogFragment
A dialog is displayed on the top of the parent activity. This displays a floating dialog.
These are the fragments for small screen devices such as smartphone.
Service perform long-running operations. It is a background process, therefore the operations run
A service starts when an activity starts it by calling startService(). After that, a service can run in
the background indefinitely. This service runs even when the component that started it is
destroyed.
service offers a client-server interface allowing components to interact with the service, send
requests, etc.
Just like an Activity, the Service base class has callback methods:
onStartCommand(): This method is called when another component requests that the service be
started calling startService(). After implementing this, you should stop the service by calling stopSelf() or
stopService() methods when the work is stopped.
onBind(): The system calls this method when another component wants to bind with the service by
calling bindService(). If you implement this method, you must provide an interface that clients use to
communicate with the service, by returning an IBinder object.
onUnbind(): The system calls this method when all clients have disconnected from a particular
interface published by the service.
onRebind(): The system calls this method when new clients have connected to the service, after it
had previously been notified that all had disconnected in its onUnbind(Intent).
onCreate(): This method is called to perform one-time setup procedures when the service is initially
created.
onDestroy(): This method is called when the service is no longer used and is being destroyed.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 68 – Why do we use Handler in Android?
A Handler in Android allows sending and processing Message and Runnable objects associated
A lot of methods are provided for scheduling messages such as postAtTime(Runnable, long),
To display a list of completion suggestions automatically when user types, use the
The following are some of the attributes for AutoCompleteTextView control in Android:
You can also add more functionalities to the AutoCompleteTextView control and customize the
2
3 <GridView xmlns:android="http://schemas.android.com/apk/res/android"
4 android:id="@+id/gridview"
5 android:layout_width="fill_parent"
6 android:layout_height="fill_parent"
7 android:columnWidth="80dp"
8 android:numColumns="auto_fit"
9 android:verticalSpacing="8dp"
10 android:horizontalSpacing="8dp"
11 android:stretchMode="columnWidth"
12 android:gravity="center"
13 />
Motion sensors: These sensors measure acceleration forces and rotational forces along three axes.
Environmental sensors: These sensors measure various environmental parameters like humidity,
pressure, etc.
Position sensors: These sensors measure the physical position of a device.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 72 – What are the tips to reduce the battery usage of your
Android app caused due to location usage?
Here are some of the tips you can follow to reduce the battery usage of your Android app caused
The difference can be understood using the following screenshot wherein LinearLayout sets a
layout in horizontal or vertical row. However, in RelativeLayout you can set the location of child
Let us now learn about these layouts to learn about more points about their differences.
The Linear Layout arranges views horizontally or vertically. For this, set the following under linear
layout:
1 android:orientation="horizontal"
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
1 android:orientation="vertical"
The following are some of the useful methods that helps in working with LinearLayout:
Relative Layout
Specify the position of child views relative to each other or parent. The following are some of the
constants of RelativeLayout:
If you want to display web pages in your application, then use the WebView. These web pages
would be displayed as part of the activity layout. It can handle a wider range of HTML tags for you
web pages.
It is displayed as:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
To get control over the WebView and customize it, use the following methods:
1 <WebView
2 android:id="@+id/webview"
3 android:layout_alignParentTop="true"
4 android:layout_alignParentLeft="true"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"/>
Now, in your Java file, create an object and get the reference:
Since it’s a WebView and you definitely want to load a URL in it to begin with. For that, the class
has the loadUrl(String url) method, in which as “url” you need to set the url:
1 w.loadUrl("http://www.google.com");
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 75 – What are the cloud backup options available for Android
app?
Auto backup
This auto backup works for Google Drive i.e. your data gets uploaded to the Drive account of the
user. You can store up to 25 MB of file-based data per app. It’s enabled by default.
Key/Value Backup
The Key/Vale Backup saves data in the form of key/value pairs by uploading it to the Android
Backup Service.
The nine- patch image has an extra 1-pixel border around the image to determine where the
image can be stretched. This stretching is to meet the specific layout constraints. The extension of
When you want to access data in a ContentProvider, you need to use the ContentResolver object
DDMS is Dalvik Debug Monitor Server that has many services on the device that includes call
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
The left pane allows you to select device. However, the right one gives information about that
Google has some tools to control the Android device. Download SDK Platform and SDK Platform-
tools to develop an Android app. One of the best know Platform Tools is ADB.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
ADB is Android Debug Bridge, which is a command-line tool to communicate with a device. You
get access to a UNIX shell with a variety of commands using the ADB command. Installing and
debugging apps also comes under ADB. You can also use adb with a device connected over USB.
Client: Client runs on the development machine. Invoke it using the abd command.
Daemon; It runs as a background process.
Server; The server manages communication between the client and the daemon.
Now extract the zip file in “C://adb”. After extracting the files, go to adb > platform-tools. This
Now, when you will type “adb”, then ADB version would be visible. This is how we got ADB on
Windows.
Here are the steps to create a custom camera interface for your app:
The custom fonts can be set for the strings in the Android app. Place the font in the following
location:
1 assets/fonts
Now, the Typeface class is the class you need to focus on for accessing the same font:
Before working on the example, let us first see the methods available to effectively work with fonts:
create(String familyName, int style): Create a Typeface object given a family name, and option
style information.
create(Typeface family, int style): Create a Typeface object that best matches the specified
existing Typeface and the specified Style.
createFromFile(String path): Create a new Typeface from the specified font file
defaultFromStyle(int style): Returns one of the default Typeface objects, based on the specified
style
getStyle(): Returns the Typeface’s intrinsic style attributes
1 <TextView
2 android:layout_width="wrap_content"
3 android:layout_height="wrap_content"
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
4 android:text="Typeface"
5 android:id="@+id/textView1"
6 android:layout_alignParentTop="true"
7 android:layout_centerHorizontal="true"
2
3 TextView tv;
4
6 super.onCreate(savedInstanceState);
7 setContentView(R.layout.activity_main);
8
9 tv =(TextView)findViewById(R.id.textView1);
10
12 tv.setTypeface(f);
13 }
14 }
Toast is used to display a short message in the bottom that is invisible after some seconds.
You can easily create a customized toast in Android. That would mean changing the color of the
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
To create a custom toast, you need to set a TextView and work it for setView():
2
4 toast.setGravity(Gravity.CENTER,0,0)
5
7 tv.setBackgroundColor(Color.BLACK);
8 tv.setTextColor(Color.WHITE)
9 tv.setTextSize(25);
10
12 tv.setTypeface(t);
15 toast.setView(tv);
16 toast.show();
17 }
18 }
2 toast.setGravity(Gravity.CENTER,0,0)
2 tv.setBackgroundColor(Color.BLACK);
3 tv.setTextColor(Color.WHITE)
4 tv.setTextSize(25);
2
3 tv.setTypeface(t);
1 toast.setView(tv);
The Android Interface Definition Language (AIDL) allows to define the programming interface that
both the client and service agree to. This is to form a communication between them using
interprocess communication (IPC).
int
long
char
String
CharSequence
List
Map
Define the AIDL interface in an .aidl file. Save it in the src/ directory of both the application hosting
the service and any other application that binds to the service.
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Create an aidl file that defines the programming interface with method signatures.
Based on the .adl file, an interface is generated by the Android SDK tools. This interface has Stub,
which is inner abstract class. This Stub extends Binder.
Implement a Service and override onBind() to return your implementation of the Stub class.
Android has some touch screen events like scrolls, pinch, double tap, long presses, etc, which are
The following methods tell more about how to handle the touch screen events:
getEventTime(): This method gets the event time of the current event being processed.
getFocusX(): This method gets the X coordinate of the current gesture’s focal point.
getFocusY(): This method gets the Y coordinate of the current gesture’s focal point.
getTimeDelta(): This method returns the time difference in milliseconds between the previous
accepted scaling event and the current scaling event.
isInProgress(): This method returns true if a scale gesture is in progress.
onTouchEvent(MotionEvent event): This method accepts MotionEvents and dispatches events
when appropriate.
To read contact from an Android device, you need the READ_CONTACTS permission.
Events gathers data about a user’s interaction with interactive components of Applications. The
following are the event handlers in Android for click events, pressing a key, selecting a menu item:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
View objects are User Interface elements in Android that responds to the user’s actions. For
The ViewGroups is the base class for layouts and views containers. These layouts include the UI
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
android:layout_weight: Specifies how much of the extra space in the layout should be allocated to
the View.
The Android apps are no longer automatically granted all of their specified permissions at the time
of installation. The users are now prompted to grant or deny individual permissions.
For protecting the privacy of Android smartphone and tablet users, a concept called Permissions
for Android apps is covered. The apps must request permissions for accessing contacts from the
contacts list, accessing SMS messages, launching Camera, Internet, allowing application to record
audio, etc.
If normal permissions are listed in its manifest, then the system automatically grants those
permissions to your app. This is because the permissions aren’t risky to the privacy of users or the
If dangerous permissions are listed in its manifest, then the user needs to explicitly agree for
granting the permissions. This is because the permissions are risky to the privacy of users or the
If you want to pass the objects to activities then you need to implement the Serializable or
Parcelable interface.
Serializable and Parcelable are interfaces. Serializable is a standard java interface and Parcelable
is an Android-specific interface.
The following are the differences between Serializable and Parceable in Android:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
ListView allows you to add a list of scrollable items. It is a subclass of AdapterView. RecyclerView
The following are the differences between RecyclerView and ListView in Android:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 93 – What is Android Lint. What it is typically used for?
Android Studio has a code scanning tool called lint. This tool allows in knowing and correcting the
Step3: After clicking, you need to set the “Inspection Scope”. You will get the following options:
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 94 – What are the files under Android Studio Project Directory?
A Project Directory in Android Studio has a structure that is organized by modules and files.
Let’s say we have a project named “DemoProject”. Within that we would have the “src” and “res”
directory.
2 DemoActivity.java
2 demo_activity.xml
The “strings.xml” comes under the “res/values/” folder. This is the string resource file.
Manifest
AndroidManifest.xml has key information about the Android app and it is the root of the project
source set. It consists of the package name, permissions, activity and other information about the
app.
String Resource
The string resource file is the strings.xml file. Set text strings in your application. The location of
1 res/values/strings.xml
R.java is the file that generates after compilation. It has the IDs for all the resources of the /res
1 \app\build\generated\
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 95 – How to change the Android app title?
To change the Android app title, you need to go to the AndroidManifest.xml and change the label.
Let’s say the following is the app title right now “AmitApplication”:
To change the app title, you need to update the <application> tag.
Within the <application> tag, you need to get the label value i.e.:
1 android:label="@string/app_name"
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Above, we changed the above title name from “Amit Application” to “Amit Learning
Application”
Ques 96. Can we deliver broadcast to other apps with Android Intent?
sendStickyBroadcast().
APK is Android Package Kit, which is used for the distribution and installation of mobile apps in
Android. It is generally a package file format. The APK file has the entire code, resources, assets,
onCreate() is where the activity gets initialized. It is called only once during the Activity lifecycle.
However, the onStart() method is called whenever the Activity becomes visible i.e. it makes the
JEKISHAN K. PARMAR
ANDROID PROGRAMMING (2180715)
INTERVIEW-ORIENTED QUESTIONS & ANSWERS
Ques 99. How to identify view elements in Android?
The findViewById is used in Android to identify view elements i.e. it is used to retreive and interact
message between activities, content providers, etc. The startActivity is used with Intent to launch
an Activity.
The Intents are used for Starting a service, launching an activity, displaying list of contacts, phone
Implicit Intent
The Implicit Intent define the action to be performed for different activities. These Intents do not
2 i.setAction(Intent.ACTION_SEND);
Explicit Intent
The Explicit Intent allows users to connect one activity to another. It is for an application to launch
The following is an example that connects the current activity to next activity Demo.class:
JEKISHAN K. PARMAR