Thursday, 4 June 2015

Android Interview Question and Answer for Fresher and Experience

Ques 1.What is android ?
Ans. 
Android is a stack of software for mobile devices which has Operating System middleware and some key applications. The application executes within its own process and its own instance of Dalvik Virtual Machine. Many Virtual Machines run efficiently by a DVM device. DVM executes Java language byte code which later transforms into .dex format files.

Ques 2.Explain the Architecture of Android ?  
Ans.

-> Applications (Home Contacts Browser Phone etc)
-> Application Framework (Activity Manager Window Manager Content Providers View System Package manager
Telephony manager Resource manager Notification manager Location manager)
-> System Libraries (Like SurfaceManager SQLite webkit SSL SGL OpenGL|ES Media Framework Free Type libc etc) & Android Runtime( Core Libraries and DVM).
-> Linux Kernel (which composed of drivers like display camera Flash Memory Binder(IPC) Keypad  Wi-Fi Audio Power Management etc.)


Ques 3.What are the advantages of Android ?
Ans.  
Following are the advantages of Android:

The customer will be benefited from wide range of mobile applications to choose since the monopoly of wireless carriers like AT&T and Orange will be broken by Google Android.
Features like weather details live RSS feeds opening screen icon on the opening screen can be customized.
Innovative products like the location-aware services location of a nearby convenience store etc. are some of the additive facilities in Android. Components can be reused and replaced by the application framework.
Optimized DVM for mobile devices
SQLite enables to store the data in a structured manner.
Supports GSM telephone and Bluetooth WiFi 3G and EDGE technologies
The development is a combination of a device emulator debugging tools memory profiling and plug-in for Eclipse IDE.

Ques 4. What are the components of Android ?
Ans.
Activities: It displays the UI and handles the user interaction to the smart-phone screen.
Services: It handle background processing without display any UI associated with an application.
Broadcast Receivers: It provide communication between Android OS and applications.
Content Providers: It handle data processing and database management issues.

Ques 5. What is an activity ?
Ans. A single screen in an application with supporting Java code.
An activity presents a visual user interface for one focused endeavor the user can undertake.
For example an activity might present a list of menu items users can choose from or it might display photographs along with their captions.
An activity is implemented as a subclass of Activity class as follows:

public class MainActivity extends Activity {  }

Ques 6. What is life cycle of Activity ?
Ans.
·    onCreate()        This is the first callback and called when the activity is first created.
·    onStart()           This callback is called when the activity becomes visible to the user.
·    onResume()     This is called when the user starts interacting with the application.
·    onPause()         The paused activity does not receive user input and cannot execute any code    and called when the current activity is being paused and the previous activity is being resumed.

·    onStop()           This callback is called when the activity is no longer visible.
·    onDestroy()     This callback is called before the activity is destroyed by the system.
onRestart() This callback is called when the activity restarts after stopping it.

Ques 7. What is service ?
Ans.
A service is an application component that can run some long running task in the background without the need for a user interface. Some other application component can start the service and this service will then keep on running even if the user switches to another application. It can declare the service as private in the manifest file and block access from other applications. A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process. To ensure your app is secure always use an explicit intent when starting or binding your Service and do not declare intent filters for the service.

For example a service might play background music as the user attends to other matters or it might fetch data over the network or calculate something and provide the result to activities that need it.Each service extends the Service base class.

public class MyService extends Service { }

A service can essentially take two states:
Started:     A service is started when an application component such as an activity starts it by calling startService(). Once started a service can run in the background indefinitely even if the component that started it is destroyed.

Bound:      A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service send requests get results and even do so across processes with interprocess communication (IPC).

Ques 8. What is life cycle of service ?
Ans.
startService(Intent Service)
This you must call to start un-bounded serviec

onCreate()
This method is Called when the service is first created

onStartCommand(Intent intent int flags int startId)
This method is called when service is started

onBind(Intent intent)
This method you must call if you want to bind with activity

onUnbind(Intent intent)
This method is Called when the service will un-binded from activity

onRebind(Intent intent)
This method is called when you want to Re-bind service after calling un-bind method

onDestroy()
This method is called when The service is no longer used and is being destroyed

Ques 9. What is broadcast receiver ?
Ans.
Broadcast Receivers simply respond to broadcast messages from other applications or from the system. A broadcast receiver is implemented as a subclass of BroadcastReceiver class and each message is broadcasted as an Intent object.
public class MyReceiver  extends  BroadcastReceiver { }

Ques 10. What is content provider ?  
Ans.
A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. The data may be stored in the file system the database or somewhere else entirely.

A content provider is implemented as a subclass of ContentProvider class and must implement a standard set of APIs that enable other applications to perform transactions.

public class MyContentProvider extends  ContentProvider { }     

Ques 11. What are the addition components of Android?
Ans.
Fragments: Represents a behavior or a portion of user interface in an Activity.
Views: UI elements that are drawn onscreen including buttons lists forms etc.
Layouts: View hierarchies that control screen format and appearance of the views.
Intents: Messages wiring components together.
Resources: External elements such as strings constants and drawables pictures.
Manifest: Configuration file for the application.

Ques 12.What are fragments in Android Activity ?  
Ans. Fragment represents a behavior or a portion of user interface in an Activity. And it is a self-contained component with its own UI and lifecycle.

Ques 13. What is life cycle of fragment ?
Ans. Android fragments have their own life cycle very similar to an android activity. This section briefs different stages of its life cycle.
Phase I: When a fragment gets created it goes through the following states:

onAttach()

onCreate()

onCreateView()

onActivityCreated()


Phase II: When the fragment becomes visible it goes through these states:

onStart()

onResume()

Phase III: When the fragment goes into the background mode it goes through these states:

onPaused()

onStop()

Phase IV: When the fragment is destroyed it goes through the following states:

onPaused()

onStop()

onDestroyView()

onDestroy()

onDetach()
Ques 14. Difference between Activity and FragmentActivity ?
Ans. Fragment is a part of an activity which contributes its own UI to that activity. Fragment can be thought like a sub activity. Where as the complete screen with which user interacts is called as activity. An activity can contain multiple fragments.Fragments are mostly a sub part of an activity.

An activity may contain 0 or multiple number of fragments based on the screen size. A fragment can be reused in multiple activities so it acts like a reusable component in activities.

A fragment can't exist independently. It should be always part of an activity. Where as activity can exist without any fragment in it.

Following are important points about fragment:

A fragment has its own layout and its own behavior with its own lifecycle callbacks.

You can add or remove fragments in an activity while the activity is running.

You can combine multiple fragments in a single activity to build a multi-pane UI.

A fragment can be used in multiple activities.

Fragment life cycle is closely related to the lifecycle of its host activity.

when the activity is paused all the fragments available in the acivity will also be stopped.

A fragment can implement a behavior that has no user interface component.

Fragments were added to the Android API in Honeycomb version of Android which API version 11.

Ques 15. What is view  ?
Ans.  View is the base class for widgets which are used to create interactive UI components like buttons text fields etc.

Ques 16. What is layout ?
Ans. A layout may contain any type of widgets such as buttons labels textboxes and so on.

Ques 17. What is intent ?
Ans. Intent is an object carrying an intent i.e. message that is passed between components (such as activities content providers broadcast receivers services etc. except for content Provider) within the application or outside the application.

It is mainly used to:

Start the service
Launch an activity
Display a web page
Display a list of contacts
Broadcast a message
Dial a phone call etc.

Ques 18.How many type of Intent ?
Ans. Two types of Intent:

implicit and
explicit

Explicit Intent: Explicit Intent specifies the component. In such case intent provides the external targeted activity or class to be invoked.

// Explicit Intent by specifying its class name
Intent i = new Intent(this TargetActivity.class);
i.putExtra(key1 Name);
i.putExtra(key2 Emil);

// Starts TargetActivity
startActivity(i);

Implicit Intent:

Implicit Intent doesn't specifiy the component. In such case intent provides information of available components provided by the system that is to be invoked. Implicit intents are often used to activate components in other applications

// Implicit Intent by specifying a URI
Intent i = new Intent(Intent.ACTION_VIEW
Uri.parse(http://www.example.com));

// Starts Implicit Activity
startActivity(i);

Ques 19. What is resource ?
Ans. Resources like static content that code uses such as bitmaps colors layout definitions user interface strings animation instructions and more. These resources are always maintained separately in various sub-directories under res/ directory of the project.

Ques 20. What is manifest ?
Ans. The components and settings of an Android application are described in the AndroidManifest.xml file. Before running any application code has to mention required permission activity services receiver etc in manifest file. This file is read by the Android system during installation of the application. The Android system evaluates this configuration file and determines the capabilities of the application.

Ques 21. What is viewGroup ?
Ans. The ViewGroup is a subclass of View and provides invisible container that hold other Views or other ViewGroups and define their layout properties.

Ques 22. What are the types of layout ?
Ans. There are number of Layouts provided by Android which you will use in almost all the Android applications to provide different view look and feel.

Linear Layout: LinearLayout is a view group that aligns all children in a single direction vertically or horizontally.

Relative Layout: RelativeLayout is a view group that displays child views in relative positions.

Table Layout: TableLayout is a view that groups views into rows and columns.

Absolute Layout :AbsoluteLayout enables you to specify the exact location of its children.

Frame Layout :The FrameLayout is a placeholder on screen that you can use to display a single view.

List View :ListView is a view group that displays a list of scrollable items.

Grid View : GridView is a ViewGroup that displays items in a two-dimensional scrollable grid.

Ques 23. Explain about the exceptions of Android ?
Ans. The following are the exceptions that are supported by Android
InflateException : When an error conditions are occurred this exception is thrown
Surface.OutOfResourceException: When a surface is not created or resized this exception is thrown
SurfaceHolder.BadSurfaceTypeException: This exception is thrown from the lockCanvas() method when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS
WindowManager.BadTokenException: This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken.  

Ques 24. Describe the APK format
Ans. The APK file is compressed the AndroidManifest.xml file application code (.dex files) resource files and other files. A project is compiled into a single .apk file.

Ques 25. What is .apk extension ?
Ans. The extension for an Android package file which typically contains all of the files related to a single Android application. The file itself is a compressed collection of an AndroidManifest.xml file application code (.dex files) resource files and other files. A project is compiled into a single .apk file.

Ques 26. What is .dex extension?
Ans. Android programs are compiled into .dex (Dalvik Executable) files which are in turn zipped into a single .apk file on the device. .dex files can be created by automatically translating compiled applications written in the Java programming language.
Is the innovative web software and mobile application development company which provides services across the country by expert team of software engineers at reasonable cost.


Ques 27. How to Remove Desktop icons and Widgets ?
Ans. Press and Hold the icon or widget. The phone will vibrate and on the bottom of the phone you will see anoption to remove. While still holding the icon or widget drag it to the remove button. Once remove turns red drop the item and it is gone

Ques 28. Describe a real time scenario where android can be used ?
Ans .Imagine a situation that you are in a country where no one understands the language you speak and you can not read or write. However you have mobile phone with you.

Ques 29. What languages does Android support for application development ?
Ans.Android applications are written using the Java programming language.

Ques 30. What is the Android Open Source Project ?
Ans. We use the phrase Android Open Source Project or AOSP to refer to the people the processes and the source code that make up Android.






Ques31. What is the latest Facebook SDK version?
Ans.
Facebook Android SDK 3.22

Ques32. What is the latest PayPal SDK version?
Ans.
PayPal Android SDK Release 2.8.4 one month ago

Ques 33. What is the latest Twitter SDK version?
Ans
Twitter twitter4j Android SDK Release Latest version: 1.1.1 one month ago

Ques 34. Why did we open the Android source code?
Ans.
Google started the Android project in response to our own experiences launching mobile apps. We wanted to make sure that there would always be an open platform available for carriers OEMs and developers to use to make their innovative ideas a reality. We also wanted to make sure that there was no central point of failure so that no single industry player could restrict or control the innovations of any other. The single most important goal of the Android Open-Source Project (AOSP) is to make sure that the open-source Android software is implemented as widely and compatibly as possible to everyone’s benefit.

Ques 35. Why cannot you run standard Java bytecode on Android?
Ans.
Android uses Dalvik Virtual Machine (DVM) which requires a special bytecode. We need to convert Java class files into Dalvik Executable files using an Android tool called dx. In normal circumstances developers will not be using this tool directly and build tools will care for the generation of DVM compatible files.

Ques 36. Can you deploy executable JARs on Android? Which packaging is supported by Android?
Ans.
No. Android platform does not support JAR deployments. Applications are packed into Android Package (.apk) using Android Asset Packaging Tool (aapt) and then deployed on to Android platform. Google provides Android Development Tools for Eclipse that can be used to generate Android Package.

Ques 37. Android application can only be programmed in Java?
Ans.
False. You can program Android apps in C/C++ using NDK .

Ques 38. What is an action?
Ans.
The Intent Sender desires something or doing some task
Ques 39. What are Dalvik Executable files?
Ans.
Dalvik Executable files have .dex extension and are zipped into a single .apk file on the device.

Ques 40. How does Android system track the applications?
Ans.
Android system assigns each application a unique ID that is called Linux user ID. This ID is used to track each application.

Ques 41. When does Android start and end an application process?
Ans.
Android starts an application process when application's component needs to be executed. It then closes the process when it's no longer needed (garbage collection).

Ques 42. How can two Android applications share same Linux user ID and share same VM?
Ans.
The applications must sign with the same certificate in order to share same Linux user ID and share same VM.

Ques 43. What is an Intent?
Ans.
class (Intent) which describes what a caller desires to do. The caller will send this intent to Android's intent resolver which finds the most suitable activity for the intent. E.g. opening a PDF document is an intent and the Adobe Reader apps will be the perfect activity for that intent (class).

Ques 44. What is a Sticky Intent?
Ans.
Sticky Intent is also a type of Intent which allows a communication between a function and a service sendStickyBroadcast() performs a sendBroadcast(Intent) known as sticky i.e. the Intent you are sending stays around after the broadcast is complete so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver IntentFilter). In all other ways this behaves the same as sendBroadcast(Intent). One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.

Ques 45. How the nine-patch Image different from a regular bitmap? Alternatively what is the difference between nine-patch Image vs regular Bitmap Image?
Ans .It is one of a resizable bitmap resource which is being used as backgrounds or other images on the device. The NinePatch class allows drawing a bitmap in nine sections. The four corners are unscaled; the middle of the image is scaled in both axes the four edges are scaled into one axis.

Ques 46. What is a resource?
Ans. user defined JSON XML bitmap or other file injected into the application build process which can later be loaded from code.
Ques 47.Does Android support the Bluetooth serial port profile?Does Android support the Bluetooth serial port profile?
Ans.  Yes.

Ques 48. How to Translate in Android?
Ans. The Google translator translates the data of one language into another language by using XMPP to transmit data. You can type the message in English and select the language which is understood by the citizens of the country in order to reach the message to the citizens.

Ques 49. What dialog boxes are supported in Android ?Android supports 4 dialog boxes:
Ans.
AlertDialog: An alert dialog box supports 0 to 3 buttons and a list of selectable elements including check boxes and radio buttons. Among the other dialog boxes the most suggested dialog box is the alert dialog box.


ProgressDialog: This dialog box displays a progress wheel or a progress bar. It is an extension of AlertDialog and supports adding buttons.
DatePickerDialog: This dialog box is used for selecting a date by the user.
TimePickerDialog: This dialog box is used for selecting time by the user.

Ques 50.Features of Android:
Ans.
Application framework enabling reuse and replacement of components
Dalvik virtual machine optimized for mobile devices
Integrated browser based on the open source WebKit engine
Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
SQLite for structured data storage
Media support for common audio video and still image formats (MPEG4 H.264 MP3 AAC AMR JPG PNG GIF)
GSM Telephony (hardware dependent)
Bluetooth EDGE 3G and WiFi (hardware dependent)
Camera GPS compass and accelerometer (hardware dependent)
Rich development environment including a device emulator tools for debugging memory and performance profiling and a plugin for the Eclipse IDE.


Android Interview Question Answer
Android Interview Question Answer


Ques 51.What is an Application ?
Ans. Collection of one or more activities services listeners and intent receivers. An application has a single manifest and is compiled into a single .apk file on the device.

Ques 52.What is a Content Provider ?
Ans. A class built on ContentProvider that handles content query strings of a specific format to return data in a specific format. See Reading and writing data to a content provider for information on using content providers.

Ques 53. What is a Dalvik ?
Ans. The name of Android’s virtual machine. The Dalvik VM is an interpreter-only virtual machine that executes files in the Dalvik Executable (.dex) format a format that is optimized for efficient storage and memory-mappable execution. The virtual machine is register-based and it can run classes compiled by a Java language compiler that have been transformed into its native format using the included dx tool. The VM runs on top of Posix-compliant operating systems which it relies on for underlying functionality (such as threading and low level memory management). The Dalvik core class library is intended to provide a familiar development base for those used to programming with Java Standard Edition but it is geared specifically to the needs of a small mobile device.

Ques 54.What is an DDMS ?
Ans. Dalvik Debug Monitor Service a GUI debugging application shipped with the SDK. It provides screen capture log dump and process examination capabilities.


Ques 55.What is Drawable?
Ans. A compiled visual resource that can be used as a background title or other part of the screen. It is compiled into an android.graphics.drawable subclass.

Ques 56. Android latest Version?
Ans. Android 5.1(Android L)


Ques 57.How many ways data stored in Android?
Ans.
1.SharedPreferences
2.Internal Storage
3.External Storage
4.SQLite Database
5.Network connection


Ques 58. Types of Android applications?
Ans.
1.Foreground
2.Background
3.Intermittent
4.Widget


Ques 59. Android Development Tools?
Ans. The Android SDK and Virtual Device Manager Used to create and manage Android Virtual Devices (AVD) and SDK packages.
The Android Emulator An implementation of the Android virtual machine designed to run within a virtual device on your development computer. Use the emulator to test and debug your Android applications.
Dalvik Debug Monitoring Service(DDMS) Use the DDMS perspective to monitor and control the Dalvik virtual machines on which your debugging your application.
Android Asset Packaging Tool(AAPT) Constructs the destributable Android packages files (.apk).
Android Debug Bridge(ADB) A client-server application that provedes a link to a running emulator.It lets you copy files install compiled application packages(.apk)and run shell commands.


Ques 60.Implicit Intents and Late Runtime Binding?
Ans. An implicit Intent is mechanism that lets anonymous application components service action request.
That means you can ask the system to launch an Activity that can perform a given action without knowing which application or Activity  will do so.


Ques 61. What are Native Android Actions?
Ans. Native Android applications also use Intents to launch Activities and sub Activities
ACTION-ANSWER Opens an Activity that handles immediately initiates a call using the number supplied in the Intent URI. Genereally it's considered better from to use ACTION_DIAL if possible.
ACTION_DELETE Starts an Activity hat lets you delete the data specified at that Intent's data URI.
ACTION_DIAL Brings up a dialer application with the number to dial pre-populated from the Intent URI. By default this is handled by the native Android phone dialer.
ACTION_EDIT Requests an Activity that can edit that data at the specified Intent URI.
ACTION_INSERT
ACTION_PICK
ACTION_SEARCH
ACTION_SENDTO
ACTION_SEND
ACTION_VIEW
ACTION_WEB_SEARCH


Ques 62.What is Pending Intent?
Ans.The PendingIntent class provides a mechanism for creating Intents that can be fired by another application at a later time. A pending Intent is commonly used to package an Intent will be fired in response to a future eventsuch as a widget View being clicked or a Notification being selected from the notification panel.


Ques 63. What is Adapter?
Ans. Adapter are bridging classes that bind data to Views(such as List Views) used in the user interface.
The adapter is responsible for creating for creating the child Views used to represent each item within
the parent View and providing access to the underlying data.

Ques 64.What is In-app Billing?
Ans. In-app Billing on Google Play provides a straightforward simple interface for sending In-app Billing requests and managing In-app Billing transactions using Google Play. Google Play app then conveys billing requests and responses between your application and the Google Play server.
In practice your application never directly communicates with the Google Play server. Instead your application sends billing requests to the Google Play application over interprocess communication (IPC) and receives responses from the Google Play app. Your application does not manage any network connections between itself and the Google Play server.
In-app Billing can be implemented only in applications that you publish through Google Play. To complete in-app purchase requests the Google Play app must be able to access the Google Play server over the network.
In-app billing Version 3 is the latest version supported on devices running Android 2.2 or higher that have the latest version of the Google Play store installed.

Ques 65. What are the steps to implement In-app Billing?
Ans. To implement In-app Billing in your application you need to do the following:
Add the In-app Billing library to your project.
Update your AndroidManifest.xml file.
Create a ServiceConnection and bind it to IInAppBillingService.
Send In-app Billing requests from your application to IInAppBillingService.
Handle In-app Billing responses from Google Play.
To give your app the necessary permission:
<uses-permission android:name=com.android.vending.BILLING />


Ques 66. What is Web Service?
Ans. A web service is a standard for exchanging information between different types of applications irrespective of language and platform. For example an android application can interact with java or .net application using web services.


Ques 67. Describe Android XML parsing using SAX parser ?
Ans. Android provides the facility to parse the xml file using SAX DOM etc. parsers. The SAX parser cannot be used to create the XML file It can be used to parse the xml file only.
Advantage of SAX Parser over DOM
It consumes less memory than DOM.


Ques 68. Describe Android XML parsing using DOM parser ?
Ans. We can parse the xml document by dom parser also. It can be used to create and parse the xml file.
Advantage of DOM Parser over SAX
It can be used to create and parse the xml file both but SAX parser can only be used to parse the xml file.
Disadvantage of DOM Parser over SAX
It consumes more memory than SAX.


Ques 69. Describe Android XMLPullParser ?
Ans. Android recommends to use XMLPullParser to parse the xml file than SAX and DOM because it is fast.
The org.xmlpull.v1.XmlPullParser interface provides the functionality to parse the XML document using XMLPullParser.
Events of XmlPullParser
The next() method of XMLPullParser moves the cursor pointer to the next event. Generally we use four constants (works as the event) defined in the XMLPullParser interface.
START_TAG :An XML start tag was read.
TEXT :Text content was read; the text content can be retrieved using the getText() method.
END_TAG : An end tag was read.
END_DOCUMENT :No more events are available


Ques 70. Describe about Android JSON Parser ?
Ans. JSON (Javascript Object Notation) is a programming language . It is minimal textual and a subset of JavaScript. It is an alternative to XML.
Android provides support to parse the JSON object and array.
Advantage of JSON over XML
JSON is faster and easier than xml for AJAX applications.
Unlike XML it is shorter and quicker to read and write.
It uses array.


Ques 71. What is SOAP?
Ans.   SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP communicates via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C recommendation


Ques 72. Why SOAP?
Ans. It is important for application development to allow Internet communication between programs.
Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA but HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic.

A better way to communicate between applications is over HTTP because HTTP is supported by all Internet browsers and servers. SOAP was created to accomplish this.


SOAP provides a way to communicate between applications running on different operating systems with different technologies and programming languages.


Ques 73. What is WSDL?
Ans. WSDL stands for Web Services Description Language
WSDL is written in XML
WSDL is an XML document
WSDL is used to describe Web services
WSDL is also used to locate Web services
WSDL is a W3C recommendation
The WSDL Document Structure
A WSDL document describes a web service using these major elements:
Element     Description
<types>      A container for data type definitions used by the web service
<message> A typed definition of the data being communicated
<portType>            A set of operations supported by one or more endpoints
<binding>  A protocol and data format specification for a particular port type


Ques 74. What is difference between Service and Intent service?
Ans.
When to use?

The Service can be used in tasks with no UI but shouldn't be too long. If you need to perform long tasks you must use threads within Service.

The IntentService can be used in long tasks usually with no communication to Main Thread. If communication is required can use Main Thread handler or broadcast intents. Another case of use is when callbacks are needed (Intent triggered tasks). This is a subclass of Service that uses a worker thread to handle all start requests one at a time. This is the best option if you don't require that your service handle multiple requests simultaneously. All you need to do is implement onHandleIntent() which receives the intent for each start request so you can do the background work.

How to trigger?

The Service is triggered by calling method startService().

The IntentService is triggered using an Intent it spawns a new worker thread and the method onHandleIntent() is called on this thread.

Triggered From

The Service and IntentService may be triggered from any thread activity or other application component.
Runs On

The Service runs in background but it runs on the Main Thread of the application.

The IntentService runs on a separate worker thread.

Limitations / Drawbacks

The Service may block the Main Thread of the application.

The IntentService cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.

When to stop?

If you implement a Service it is your responsibility to stop the service when its work is done by calling stopSelf() or stopService(). (If you only want to provide binding you don't need to implement this method).

The IntentService stops the service after all start requests have been handled so you never have to call stopSelf().


Ques 75. What is database version?
Ans. Database version specify the current database version which is used.It can be increased through change the database schema using onUpgrade() method or drop the existing database and recreate it using onCreate() method.


Ques 76. What is difference between version code and version number in android manifest?
Ans.
version code(android:versionCode)-Version code represents the version of the application code relative to other versions(means previous .apk release version).For example at the first release of .apk of app is 1 then after modification or add any new feature in your app at that time release .apk version code will be 2.

Version Name(android:versionName)- It is a string value that represent the  release version of application code system does not use this value for any internal purpose.
For example: 1.0 or 1.0.0 formate

VersionName 1.0 > VersionCode 1
VersionName 1.1 > VersionCode 2
VersionName 1.2 > VersionCode 3
VersionName 2.0 > VersionCode 4


Ques 77.What is minSdkVersion targetSdkVersion and maxSdkVersion?
Ans. minSdkVersion(android:minSdkVersion) — The minimum version of the Android platform on which the application will run specified by the platform's API Level identifier.

targetSdkVersion(android:targetSdkVersion) — Specifies the API Level on which the application is designed to run. In some cases this allows the application to use manifest elements or behaviors defined in the target API Level rather than being restricted to using only those defined for the minimum API Level.

maxSdkVersion(android:maxSdkVersion) — The maximum version of the Android platform on which the application is designed to run specified by the platform's API Level identifier.


Ques 78. what is difference between intent and intent filter in android?
Ans. Intent:Intent is an object carrying an intent i.e. message that is passed between components (such as activities content providers broadcast receivers services etc. except for contentProvider) within the application or outside the application.

Intent-filter: Intent filter specifies the type of intents it accepts based on the intent's action data and category.Each intent filter is defined by an <intent-filter> element in the app's manifest file.An intent filter is not a secure way to prevent other apps from starting your components. Although intent filters restrict a component to respond to only certain kinds of implicit intents


Ques 79. what is Admob?
Ans. AdMob is a leading global mobile advertising network that helps app developers monetize and promote their mobile and tablet apps with ads.


Ques 80. Difference between Log and System.out.println?
Ans. if we want to trace the android project
we can do it using Log class
there is some methods like
Log.e(TAGMESSAGE)
Log.v(TAGMESSAGE)
Log.w(TAGMESSAGE)
Log.d(TAGMESSAGE)
Log.i(TAGMESSAGE)
Its a static method of Utils package. put it line by line and u can watch it in the LogCat..
thats at enjoy with android.

System.out.println() in android will not run well because there is no Terminal that the app is corrected to.

You would be better off using Log.(d)(v)(e)(i)(w) because there is something actively monitoring LogCat.

System.out.println() will print to LogCat but only after an additional set of System instructions making it not as efficient.


Ques 81. What is Google Wallet?
Ans. Google Wallet is a mobile payment system developed by Google that allows its users to store debit cards credit cards loyalty cards and gift cards among other things as well as redeeming sales promotions on their mobile phone.Google Wallet can use near field communication (NFC) to make secure payments fast and convenient by simply tapping the phone on any PayPass-enabled terminal at checkout.


Ques 82. What is AAPT?
Ans. AAPT(Android Asset Packaging Tool):which is used to list add and remove files in an APK file package resources crunching PNG files etc.This tool allows you to view create and update Zip-compatible archives (zip jar apk). It can also compile resources into binary assets.The apk file for each app contains all of the information necessary to run your application on a device or emulator such as compiled .dex files (.class files converted to Dalvik byte code) a binary version of the AndroidManifest.xml file compiled resources (resources.arsc) and uncompiled resource files for your application.


Ques 83. What is difference between sqlite and shared preferences in android?
Ans. Storing app data is an essential requirement of most applications. Android lets your store data using Shared Preferences and Sqlite database. You can use either of them based on your requirement.

Shared Preferences

Shared Preferences stores data as key-pairs only. Key is required to read data from it. Reading and storing data in it is very simple .But it’s difficult to store and read large structured data . It saves  primitives data type like string int booleans floats long etc. It is best to use Shared Preferences when only small amount of data needs to be stored eg few app settings user login /password etc.

Sqlite Database

It stores structured data as a database. The data can be queried and hence this makes it possible to search database. Reading data from sqlite database is slower and more expensive than shared preferences. SQLite database is useful for just about anything and very flexible. It is best to use Sqlite when the data to be stored is large  structured and required searching .eg storing complete user details  storing data fetched by http request etc.


Ques 84. Difference between service and intentService When to use?
Ans.
The Service can be used in tasks with no UI but shouldn't be too long. If you need to perform long tasks you must use threads within Service.

The IntentService can be used in long tasks usually with no communication to Main Thread. If communication is required can use Main Thread handler or broadcast intents. Another case of use is when callbacks are needed (Intent triggered tasks).

How to trigger?

The Service is triggered by calling method startService().

The IntentService is triggered using an Intent it spawns a new worker thread and the method onHandleIntent() is called on this thread.

Triggered From

The Service and IntentService may be triggered from any thread activity or other application component.
Runs On

The Service runs in background but it runs on the Main Thread of the application.

The IntentService runs on a separate worker thread.

Limitations / Drawbacks

The Service may block the Main Thread of the application.

The IntentService cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.

When to stop?

If you implement a Service it is your responsibility to stop the service when its work is done by calling stopSelf() or stopService(). (If you only want to provide binding you don't need to implement this method).

The IntentService stops the service after all start requests have been handled so you never have to call stopSelf().


Android Interview QA
Android Interview QA


Ques 85. What is GCM?
Ans.    Google Cloud Messaging (GCM) for Android is a service that allows to send data from third party server (on which app is running) to user’s Android-powered device which installed GCM integrated app and also to receive messages from devices on the same connection. The GCM service handles all aspects of queuing of messages and delivery to the target Android application running on the target device and it is completely free.
It is light weight message containing up to 4kb of payload data. GCM is completely free no matter how big your messaging needs are and there are so far no quotas.

GCM connection servers take messages from a 3rd-party application server (written by you) and send them to a GCM-enabled Android application (the client app also written by you) running on a device.

Need Google Account if the device is running a version lower than Android 4.0.4

Ques 86. What are the steps to process of GCM?
Ans.
Android device sends SENDER_ID to GCM server for registration.
After successful registration GCM server return registration ID to Android Device.
After getting registration ID android device send registration ID to web server.
Store GCM registration ID in our database at server.
Whenever PUSH notification needed get RegID from our database and send request to GCM with RegID and message.
After got Push notification request GCM send Push notification to Android device.

Ques 87. Key points to integrate GCM (Google Cloud Messaging) in Android App?
Ans.       1. Crating Google API Project
Open the Google Developers Consol.
Click on create project input project name once project is created a page appears that displays project ID and project Number like project number: 670330092345 later it will use in project code to as GCM Sender ID.

2. Enabling the GCM Service
To enable the GCM service:
In the sidebar on the left select APIs & auth.
In the displayed list of APIs turn the Google Cloud Messaging for Android toggle to ON.

3. Obtaining an API Key
To obtain an API key:
In the sidebar on the left select APIs & auth > Credentials.
Under Public API access click Create new key.
In the Create a new key dialog click Server key.
In the resulting configuration dialog supply your server's IP address. For testing purposes you can use 0.0.0.0/0.
Click Create.
In the refreshed page copy the API key. You will need the API key later on to perform authentication in your application server.

Once finish these steps have to decide which type GCM connection server want to use HTTP or XMPP(CSS).

GCM HTTP:
Downstream only: cloud-to-device.

3rd-party app servers send messages as HTTP POST requests and wait for a response. This mechanism is synchronous and causes the sender to block before sending another message.

JSON messages sent as HTTP POST.

CCS:
Upstream and downstream (device-to-cloud cloud-to-device).

3rd-party app servers connect to Google infrastructure using a persistent XMPP connection and send/receive messages to/from all their devices at full line speed. CCS sends acknowledgment or failure notifications (in the form of special ACK and NACK JSON-encoded XMPP messages) asynchronously.

JSON messages encapsulated in XMPP messages.


Ques 88. What are the permissions to use in manifest file to integrate GCM?
Ans. <uses-permission android:name=android.permission.INTERNET />
permission so that Android application can send the registration ID to the 3rd party server.

<uses-permission android:name=android.permission.ACCESS_NETWORK_STATE />
Network State Permissions to detect Internet status

<uses-permission android:name=android.permission.GET_ACCOUNTS />
permission as GCM requires a Google account (necessary only if if the device is running a version lower than Android 4.0.4)

<uses-permission android:name=android.permission.WAKE_LOCK />
permission so the application can keep the processor from sleeping when a message is received. Optional—use only if the app wants to keep the device from sleeping.

<uses-permission android:name=com.google.android.c2dm.permission.RECEIVE />
permission so the Android application can register and receive messages.

<permission android:name=com.example.gcm.permission.C2D_MESSAGE
android:protectionLevel=signature />
permission to prevent other Android applications from registering and receiving the Android application's messages. The permission name must exactly match this pattern—otherwise the Android application will not receive the messages.

<uses-permission android:name=com.example.gcm.permission.C2D_MESSAGE />


Ques 89.How to integrate PayPal with Android Application?
Ans. To integrate the MPL into an Android app you need to:

Download the Android Mobile Payments Library SDK from PayPal and include PayPal_MPL.jar and the other necessary MPL components in your Android app.
Obtain an AppID (for testing purposes use the PayPal Sandbox AppID).
Specify the PayPal environment you're addressing (for example ENV_SANDBOX or ENV_LIVE) and the business' PayPal Account as the receiver.
Calculate the price of the item(s) or service to be purchased and input that value into your MPL call.
Set the Payment Type (for example PAYMENT_TYPE_SERVICE or PAYMENT_TYPE_PERSONAL).
Make the MPL payment call.
When you make the call the customer is presented with an in-app PayPal log in screen and the payment processing is completed within your app (there is no browser or webview involved).

When the payment flow is complete MPL returns control to your app.

Ques 90. How to inject PayPal jar file in android app?
Ans.     To add the library .jar file to an eclipse project:
Right-click your project in eclipse and select Properties.
Select Java Build Path.
Select the Libraries tab.
Select the Add Jars button.
Choose PayPal_MPL.jar from your folder structure and click OK.


Ques 91.What are the permission need in manifest to integrate PayPal?
Ans.
<uses-permission android:name=android.permission.INTERNET />
<uses-permission android:name=android.permission.READ_PHONE_STATE />


Ques 92. What are the programming steps to integrate Paypal with andoriud app?
Ans.
Initialize the library with the initWithAppID method.
public void initLibrary() {
PayPal pp = PayPal.getInstance();

if (pp == null) {  // Test to see if the library is already initialized

// This main initialization call takes your Context AppID and target server
pp = PayPal.initWithAppID(this APP-80W284485P519543T PayPal.ENV_NONE);

// Required settings:

// Set the language for the library
pp.setLanguage(en_US);

// Some Optional settings:

// Sets who pays any transaction fees. Possible values are:
// FEEPAYER_SENDER FEEPAYER_PRIMARYRECEIVER FEEPAYER_EACHRECEIVER and FEEPAYER_SECONDARYONLY
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);

// true = transaction requires shipping
pp.setShippingEnabled(true);

_paypalLibraryInit = true;
}
}
Implement the getPayButton method.
Add a delegate to handle the response returned by the library.
The handler will call one of three types (paymentSucceeded paymentCanceled paymentFailed) based on the result.

public void PayPalActivityResult(int requestCode int resultCode Intent intent) {
switch (resultCode) {
// The payment succeeded
case Activity.RESULT_OK:
String payKey = intent.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
this.paymentSucceeded(payKey);
break;

// The payment was canceled
case Activity.RESULT_CANCELED:
this.paymentCanceled();
break;

// The payment failed get the error from the EXTRA_ERROR_ID and EXTRA_ERROR_MESSAGE
case PayPalActivity.RESULT_FAILURE:
String errorID = intent.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
String errorMessage = intent.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
this.paymentFailed(errorID errorMessage);
}
}



Ques 93. What are the steps to integrate Facebook using Facebook SDK in android app?
Ans.
Create a Development Key Hash
Go to Facebook login after login  click on profile pick will get drop-down list  click on Developer Setting  and generate 28 character App ID by putting Package Name App Name and Key Hashes.
Download the Facebook SDK and unzip it and import the Facebook SDK in Eclipse by follow steps:
Go to Eclipse's File > Import Menu
Select General > Existing Projects into Workspace
Browse to the folder where you unzipped the SDK and click Open
Uncheck'Copy projects into workspace' so sample projects retains a correct reference to the neighboring SDK
Click Finish to import the SDK.
To add the SDK to an existing Android Project in Eclipse link your project to the Facebook SDK library project you imported.
View the properties for your project
Click Android tab.
Click Add
Choose FacebookSDK project from the workspace.
Then add your Facebook App ID into your project's strings file:
Open your res/values/strings.xml file
Add a new string entry with the name facebook_app_id and value as your Facebook App ID
Update your Android Manifest:
Open your AndroidManifest.xml file
In the Permissions tab add a new uses-permission: android.permission.INTERNET
In the Application tab add new meta-data with the name com.facebook.sdk.ApplicationId and the value @string/facebook_app_id


Ques 94. What are the steps to integrate Twitter using Twitter SDK in android app?
Ans. First of all have to register in twitter and register your application and get application id provided by twitter.
To register application have to provide Application Name Description and Website(optional).
In the permission select Read and Write option.

Go to Application Setting tab and note down the API Key and API Secret to use in application.

[ private static String CONSUMER_KEY = Your API Key here;
private static String CONSUMER_SECRET = Your API Secret here;]

Download twitter SDK(Twitter4j) and add with project by right click on project.
View the properties for your project
Click Android tab.
Click Add
Choose Twitter SDK project from the workspace.
Ques 95. What’s so special about Android?
Ans. Unlike the proprietary iPhone operating system (now known as iOS) which is under the complete control of Apple — and the same goes for Research in Motion’s BlackBerry OS or Microsoft’s Windows Phone platform — Google released Android as an open-source OS under the auspices of the Open Handset Alliance leaving phone manufacturers (relatively) free to tweak Android as they see fit for a given handset.
That’s one thing that’s special about Android. Another thing is that it just happens to be a really good OS the first one in the post-iPhone wireless era to really give Apple a run for its money. Android may not be as sleek or polished as iOS (that’s my humble opinion at least) but it’s fast and powerful with an intuitive user interface that’s packed with options and flexibility. It’s also being constantly improved courtesy of the big brains at Google making the Android experience sleeker by the day.


Ques 96. Are Android phones called Droids?
Ans. Not necessarily. Droid is a brand name used by Verizon Wireless for its Android-based phones — the Droid X the Droid Eris the Droid Incredible and so on. The HTC Evo 4G on Sprint is not a Droid per se but it’s still an Android smartphone.


Ques 97. Why would I (potentially) choose an Android phone over an iPhone?
Ans. Well for a variety of reasons — although I should point out that I’m actually a fan of both operating systems. (Sorry to disappoint the smartphone flame warriors out there.)
One reason to go the Google way is that Android phones boast tight integration with Google services like Gmail Google Calendar Google Contacts and Google Voice — perfect for anyone who uses Google for all their e-mails contacts and events. Indeed one of the coolest things about Android phones is that the first time you fire one up you enter your Google user name and password and voila: All your Google messages contacts and other info start syncing into your new handset automatically no desktop syncing needed.
Android is also far more open when it comes to applications. Whereas Apple takes a walled garden approach to its App Store Google won’t restrict you from installing apps that aren’t featured in its official Android Marketplace. iPhone users on the other hand must jailbreak their phones if they want to install apps that weren’t approved by Apple for inclusion in the App Store.
Last but not least because Android is open to all manufacturers a wide variety of Android phones are available to choose from — big and small souped-up and pared-down some with slide-out keyboards (good luck convincing Steve Jobs to put a slide-out QWERTY on the iPhone) and some that are all-touchscreen all the time. Indeed in the past few months a new Android phone has debuted practically every week while we only get a single new iPhone each year.


Ques 98. What are the downsides of Android?
Ans. Well if you ask me the Android OS isn’t quite as forgiving to wireless beginners as the iPhone is. Setting up your e-mail contacts and calendar on Android is a breeze (if you’re all about Gmail that is) but when it comes to say your music and videos you’re on your own with Android which lacks an official media syncing client for the desktop. With the iPhone you do all your syncing on easy-to-use iTunes which also lets you manage your e-mail accounts contacts apps and photos. Then again you can only use iTunes for syncing the iPhone while Android users have a variety of third-party options.
That’s just one example but in general Android gives you more options and choices about how you manage your phone and your mobile content — great for experienced and advanced users but potentially intimating for new mobiles.
On the other hand while beginners might appreciate the (usually) smooth user-friendly experience that Apple has devised for the iPhone advanced users may (and often do) get frustrated by Apple’s tight control over what they can and can't do on the iPhone. It’s a trade-off plain and simple and your choice of platform depends on what’s right for you.


Ques 99. What is Mono for Android?
Ans. Mono for Android is a software development kit that allows developers to use the C# language to create mobile applications for Android-based devices.Mono for Android exposes two sets of APIs the core .NET APIs that C# developers are familiar with as well as a C# binding to Android's native APIs exposed through the Mono.Android.* namespace.You can use Mono for Android to develop applications that are distributed through the Android Application Stores or to deploy software to your personal hardware or the Android simulator.


Ques 100. What is included in Mono for Android?
Ans. Mono for Android consists of the core Mono runtime the Mono for Android bindings to the native Android APIs a Visual Studio 2010 plugin to develop Android applications and an SDK that contains the tools to build debug and deploy your applicationsOur Visual Studio 2010 plugin allows developers to use Visual Studio 2010 to develop debug and deploy their applications to an Android simulator an Android device or the Android Application Store.
Our MonoDevelop IDE also ships an addin to support Mono for Android development.


Ques 101. What do I need to develop Mono for Android applications?
Ans. Mono for Android on Windows provides a plugin for Visual Studio 2010 Professional or better. We also support Mono for Android development using MonoDevelop on Windows for users that do not own a copy of Visual Studio 2010 Professional or better.Mono for Android on Mac developers can use MonoDevelop.On all platforms Mono for Android requires the Android SDK (which requires Java JDK).


Ques 102. What are the features of Android 5.0 Lollipop (API level 21) ?
Ans.
Android Runtime (ART) with ahead-of-time (AOT) compilation and improved garbage collection (GC) replacing Dalvik that uses just-in-time (JIT) compilation.

Support for 64-bit CPUs

OpenGL ES 3.1 and Android Extension Pack (AEP) on supported GPU configurations

Vector drawables which scale without losing definition

Support for print previews

Material design bringing a restyled user interface

Refreshed lock screen no longer supporting widgets

Refreshed notification tray and quick settings pull-down

Project Volta for battery life improvements

Searches can be performed within the system settings for quicker access to particular settings

Lock screen provides shortcuts to application and notification settings

Guest logins and multiple user accounts are available on more devices such as phones.

Audio input and output through USB devices


Addition of 15 new languages: Basque Bengali Burmese Chinese (Hong Kong) Galician Icelandic Kannada Kyrgyz Macedonian Malayalam Marathi Nepali Sinhala Tamil and Telugu

Tap and Go allows users to quickly migrate to a new Android device using NFC and Bluetooth to transfer Google Account details configuration settings user data and installed applications.

A flashlight-style application is included working on supported devices with a camera flash.

User-customizable priorities for application notifications


Ques 103. What are the features of Android 4.4 KitKat (API level 19) ?
Ans.
Full-screen Immersive Mode

Now you can switch to full-screen to see more and simply swipe from the top or bottom edge of the screen to get the buttons back.


Ok Google

If you're familiar with Google Glass then you'll know saying 'Ok Glass' will activate voice control. Well the same is now true for your smartphone except you say 'Ok Google'. This will let you voice search send a text get directions or play a song - as long as you're on the homescreen on in Google Now.


Improved multi-tasking

Multi-tasking is pretty good in Android already but Google says it's even better in KatKat

Low-power audio playback

Android 4.4 allows for more hours of audio playback up to 60 hours on Nexus 5 according to Google.


Calls and messages

The new phone app orders your contacts based on the ones to interact with most and you can also search for contacts or nearby places in the search bar.

Printing

Now you can print photos documents and web pages directly from your phone or tablet. You can print to any printer connected to Google Cloud Print HP ePrint printers and others that have apps in the Google Play Store.

Chrome web view

Applications that embed web content now use Chrome to render web components accurately and quickly.

Device management built-in

If should lose your precious smartphone or tablet you can find or remote wipe it with Google's Android Device Manager.

Downloads app redesign

Google has given the Downloads app a redesigned adding a new sorting options plus list and grid views for all the files you've er downloaded.

Easy home screen switching

If you love customising to the extent that you have installed one or more home screen replacements you can switch between them easily in 'Home' section of the settings menu.

Email app refresh

The Email app has also had a makeover with a new look nested folders contact photos and better navigation.

Full-screen wallpapers with preview

Wallpapers now display through the status bar and navigation bar. When picking a new wallpaper you can preview what it will look like.

HDR+ photography

If you're getting the Nexus 5 its HDR+ mode snaps a burst of photos and combines them to give you the best possible single shot.

Infrared blasting

Android now supports applications for remote control of TVs and other nearby devices if you have an infrared (IR) transmitter.

Location in Quick Settings

There is now a new tile for location settings in the Quick Settings drop down menu.

Location modes and monitoring

If you make your battery last longer by constantly switching GPS Wi-Fi and mobile data on and off then there's an easier way in KitKat. You can choose between 'high accuracy' and 'battery-saving' location modes in the settings menu. You can also see which apps have recently requested your location.

Music and movie-seeking and artwork on the lock screen

From the lock screen you can jump to a specific part of a song or video with a long press on the play or pause buttons. Artwork is now fills the lockscreen too.

Secure app sandboxes

Application sandboxes have been hardened with Security-Enhanced Linux.

Step counting built-in

If you don't want to spend money on a fitness gadget then the Nexus 5 can act as a pedometer to count your steps. Google says updated hardware and software make this a more battery-friendly way to measure your activity.


Ques 104. What is the difference between gravity and layout_gravity ?
Ans.  android:gravity- sets the gravity of the content of the View within its used on.
android:layout_gravity- sets the gravity of the View or Layout with respect to its parent.
Ques 105. What is difference between padding and margin?
Ans.  Padding is the space inside the border between the border and the actual view's content. Note that padding goes completely around the content: there is padding on the top bottom right and left sides (which can be independent).
Margins are the spaces outside the border between the border and the other elements next to this view. In the image the margin is the grey area outside the entire object. Note that like the padding the margin goes completely around the content: there are margins on the top bottom right and left sides. In LinearLayout margin is supported in AbsoluteLayout (considered obsolete now) - no.
Ques 106. What is marqueeRepeatLimit textview attribute in android?
Ans.  The number of times to repeat the marquee animation. Only applied if the TextView has marquee enabled.
marquee_forever   or -1       Indicates that marquee should repeat indefinitely.
Ques 107. What is Ems in android?
Ans.  Ems is a typography term it controls text size etc. but only when the layout_width is set to wrap_content. Other layout_width values override the ems width setting.
Ques 108. What is dp and sp units?
Ans.  Different screens have different pixel densities so the same number of pixels may correspond to different physical sizes on different devices.
When specifying dimensions always use either dp or sp units.
A dp is a density-independent pixel that corresponds to the physical size of a pixel at 160 dpi. 
A sp is the same base unit but is scaled by the user's preferred text size (it’s a scale-independent pixel) so you should use this measurement unit when defining text size (but never for layout sizes).
Ques 109. What is the fundamental concept to generate images for different size of screens?
Ans.  Since Android runs in devices with a wide variety of screen densities you should always provide your bitmap resources tailored to each of the generalized density buckets: low medium high and extra-high density. This will help you achieve good graphical quality and performance on all screen densities.
To generate these images you should start with your raw resource in vector format and generate the images for each density using the following size scale:
xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75
This means that if you generate a 200x200 image for xhdpi devices you should generate the same resource in 150x150 for hdpi 100x100 for mdpi and finally a 75x75 image for ldpi devices.
Then place the generated image files in the appropriate subdirectory under res/
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
Ques 110. What are the directories in an application that provides different layout designs for different screen sizes and different bitmap drawables?
Ans.  Following are the list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium high and extra-high-density screens.

res/layout/my_layout.xml              // layout for normal screen size (default)
res/layout-large/my_layout.xml        // layout for large screen size
res/layout-xlarge/my_layout.xml       // layout for extra-large screen size
res/layout-xlarge-land/my_layout.xml  // layout for extra-large in landscape orientation

res/drawable-mdpi/my_icon.png         // bitmap for medium-density
res/drawable-hdpi/my_icon.png         // bitmap for high-density
res/drawable-xhdpi/my_icon.png        // bitmap for extra-high-density
res/drawable-xxhdpi/my_icon.png        // bitmap for extra-extra-high-density
Some values you might use here for common screen sizes:
Ques 111.What are the different screen configurations for different devices?
Ans.  320 for devices with screen configurations such as:
240x320 ldpi (QVGA handset)
320x480 mdpi (handset)
480x800 hdpi (high-density handset)
480 for screens such as 480x800 mdpi (tablet/handset).
600 for screens such as 600x1024 mdpi (7 tablet).
720 for screens such as 720x1280 mdpi (10 tablet).

Ques 112. What is Screen Size?
Ans.  Actual physical size measured as the screen's diagonal.
For simplicity Android groups all actual screen sizes into four generalized sizes: small normal large and extra-large.

Ques 113. What is Screen density?
Ans.  The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch). For example a low density screen has fewer pixels within a given physical area compared to a normal or high density screen.
For simplicity Android groups all actual screen densities into six generalized densities: low medium high extra-high extra-extra-high and extra-extra-extra-high.

Ques 114. What is Orientation?
Ans.  The orientation of the screen from the user's point of view. This is either landscape or portrait meaning that the screen's aspect ratio is either wide or tall respectively. Be aware that not only do different devices operate in different orientations by default but the orientation can change at runtime when the user rotates the device.
Ques 115. What is Resolution?
Ans.  The total number of physical pixels on a screen. When adding support for multiple screens applications do not work directly with resolution; applications should be concerned only with screen size and density as specified by the generalized size and density groups.
Ques 116. What is Density-independent pixel (dp)?
Ans.  A virtual pixel unit that you should use when defining UI layout to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen which is the baseline density assumed by the system for a medium density screen. At runtime the system transparently handles any scaling of the dp units as necessary based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example on a 240 dpi screen 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI to ensure proper display of your UI on screens with different densities.
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp

Ques 117. How to start another Activity from one Activity?
Ans.  Using Intent and startActivity() method.
Intent intent = new Intent(Activity1.this Activity2.class);
startActivity(intent);
Ques 118. What is ViewHolder?
Ans.  ViewHolder is use to smooth scrolling of ListView which keep the application’s main thread free from heavy processing.
A ViewHolder object stores each of the component views inside the tag field of the Layout so you can immediately access them without the need to look them up repeatedly.
Ques 119. How to implement ViewHolder programmatically?
Ans.  First you need to create a class to hold your exact set of views.
static class ViewHolder {
TextView text;
ImageView icon;
ProgressBar progress;
int position;
}
Then populate the ViewHolder and store it inside the layout.
ViewHolder holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.listitem_image);
holder.text = (TextView) convertView.findViewById(R.id.listitem_text);
holder.progress = (ProgressBar) convertView.findViewById(R.id.progress_spinner);
convertView.setTag(holder);
Ques 120. What is getView ?
Ans.  Get a View that displays the data at the specified position in the data set. You can either create a View manually or inflate it from an XML layout file. When the View is inflated the parent View (GridView ListView...) will apply default layout parameters unless you can use inflate(int android.view.ViewGroup boolean) to specify a root view and to prevent attachment to the root.
Ques 121. Describe getView parameters?
Ans.  public abstract View getView (int position View convertView ViewGroup parent)
position:      The position of the item within the adapter's data set of the item whose view we want.
convertView:             The old view to reuse if possible.If it is not possible to convert this view to display the correct data this method can create a new view.
Parent:         The parent that this view will eventually be attached to Returns.
Ques 122. What is Adapter?
Ans.  An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.
Ques 123. How many types of Adapter are used in Android?
Ans.  Three types of Adapter are used in Android:
1.ArrayAdapter : It esxtends BaseAdapter  and implement Filterable. A concrete BaseAdapter that is backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource.
2.CursorAdapter: It esxtends BaseAdapter  and implement Filterable. The Cursor must include a column named _id or this class will not work. Additionally using MergeCursor with this class will not work if the merged Cursors have overlapping values in their _id columns.
3.SimpleCursorAdapter: It extends ResourceCursorAdapter. An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want which views you want to display the columns and the XML file that defines the appearance of these views.
Ques 124. Explain ArrayAdapter parameters?
Ans.  public ArrayAdapter (Context context int resource int textViewResourceId)

Parameters
context:The current context.
resource: The resource ID for a layout file containing a layout to use when instantiating views.
textViewResourceId:             The id of the TextView within the layout resource to be populated.

Ques 125. Explain CursorAdapter parameters?
Ans.  public CursorAdapter (Context context Cursor c boolean autoRequery)
Constructor that allows control over auto-requery. It is recommended you not use this but instead CursorAdapter(Context Cursor int). When using this constructor FLAG_REGISTER_CONTENT_OBSERVER will always be set.
Parameters
context: The context
c: The cursor from which to get the data.
autoRequery: If true the adapter will call requery() on the cursor whenever it changes so the most recent data is always displayed. Using true here is discouraged.
Ques 126. Explain SimpleCursorAdapter parameters?
Ans.  public SimpleCursorAdapter (Context context int layout Cursor c String[] from int[] to int flags)
Standard constructor.
Parameters
context: The context where the ListView associated with this SimpleListItemFactory is running
layout: resource identifier of a layout file that defines the views for this list item. The layout file should include at least those named views defined in to
c: The database cursor. Can be null if the cursor is not available yet.
from: A list of column names representing the data to bind to the UI. Can be null if the cursor is not available yet.
to:  The views that should display column in the from parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. Can be null if the cursor is not available yet.
flags: Flags used to determine the behavior of the adapter as per CursorAdapter(Context Cursor int).
Ques 127. How to communicate one fragment to another fragment?
Ans.  All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly.
To allow a Fragment to communicate up to its Activity you can define an interface in the Fragment class and implement it within the Activity. The Fragment captures the interface implementation during its   onAttach() lifecycle method and can then call the Interface methods in order to communicate with the Activity.
Ques 128. Programmatically how to send values from one to another fragment?
Ans.  ArticleFragment    newFragment = new ArticleFragment();
Bundle args = new Bundle();
args.putInt(ArticleFragment.ARG_POSITION position);
newFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container newFragment);
transaction.addToBackStack(null);
transaction.commit();

Ques 129. How to pass value from one Activity to another Activity?
Ans.  Using intent can pass value from one Activity to another Activity.
Intent intent = new Intent(Activity1.this Activity2.class);
intent.putExtra(Key value);
startActivity(intent);
Get data in Activity2
Intent i=getIntent();
String    message=i.getStringExtras(Key);

Ques 130. How to pass int value from one Activity to another Activity?
Ans.  Using intent can pass value from one Activity to another Activity.
Activity 1:
Intent intent = new Intent(Activity1.this Activity2.class);
intent.putExtra(Key int_variable);
startActivity(intent);
Activity 2:
Intent intent = getIntent();
int temp = intent.getIntExtra(int_value 0); // here 0 is the default value

Ques 131. How to pass image from one Activity to another Activity?
Ans.  Can pass image using two methods from one Activity to another Activity.
Method One:
Activity 1:
Intent intent=new Intent(Activity1.this Activity2.class);
Bundle bundle=new Bundle();
bundle.putInt(imageR.drawable.ic_launcher);
intent.putExtras(bundle);
startActivity(intent);
Activity :2
Bundle bundle=this.getIntent().getExtras();
int pic=bundle.getInt(image);
v.setImageResource(pic);
Method Two:
Activity 1:
Drawable drawable=imgv.getDrawable();
Bitmap bitmap= ((BitmapDrawable)drawable).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG 100 baos);
byte[] b = baos.toByteArray();
Intent intent=new Intent(Activity1.this Activity2.class);
intent.putExtra(picture b);
startActivity(intent);
Activity2:
Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray(picture);
Bitmap bmp = BitmapFactory.decodeByteArray(b 0 b.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);

Ques 132. How to expose your private data to other applications?
Ans.  Android provides a way for expose even private data to other applications with a content provider. A content provider is an optional component that exposes read/write access to your application data.

Ques 133. What is Shared Preferences?
Ans.  The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans floats ints longs and strings. This data will persist across user sessions.It also create the user preference to choose the user prefer setting selection.
Ques 134. How to get shared preferences?
Ans.  To get a SharedPreferences object for your application use one of two methods:

getSharedPreferences() - Use this if you need multiple preferences files identified by name which you specify with the first parameter.
getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity you don't supply a name.
Ques 135. How to read and write value in shared preferences?
Ans.
To write values:
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.saved_high_score) newHighScore);
editor.commit();
Call edit() to get a SharedPreferences.Editor.
Add values with methods such as putBoolean() and putString().
Commit the new values with commit()
To read value
To retrieve values from a shared preferences file call methods such as getInt() and getString() providing the key for the value you want

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
int defaultValue = getResources().getInteger(R.string.saved_high_score_default);
long highScore = sharedPref.getInt(getString(R.string.saved_high_score) defaultValue);

Ques 136. What is REST?
Ans.
REST stands for Representational State Transfer. (It is sometimes spelled ReST.) It relies on a stateless client-server cacheable communications protocol -- and in virtually all cases the HTTP protocol is used.

REST is an architecture style for designing networked applications. The idea is that rather than using complex mechanisms such as CORBA RPC or SOAP to connect between machines simple HTTP is used to make calls between machines.

In many ways the World Wide Web itself based on HTTP can be viewed as a REST-based architecture. RESTful applications use HTTP requests to post data (create and/or update) read data (e.g. make queries) and delete data. Thus REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

REST is a lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP WSDL et al.). Later we will see how much more simple REST is.

Despite being simple REST is fully-featured; there's basically nothing you can do in Web Services that can't be done with a RESTful architecture. REST is not a standard. There will never be a W3C recommendataion for REST for example. And while there are REST programming frameworks working with REST is so simple that you can often roll your own with standard library features in languages like Perl Java or C#.
One of the best reference I found when I try to find the simple real meaning of rest.
REST is using the various HTTP methods (mainly GET/PUT/DELETE) to manipulate data.
RESTful applications use HTTP requests to post data (create and/or update) read data (e.g. make queries) and delete data. Thus REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.
Ques 137. REST vs SOAP
Ans.  A nice analogy for REST vs. SOAP is mailing a letter: with SOAP you're using an envelope; with REST it's a postcard. Postcards are easier to handle (by the receiver) waste less paper (i.e. consume less bandwidth) and have a short content. (Of course REST requests aren't really limited in length esp. if they use POST rather than GET.)

But don't carry the analogy too far: unlike letters-vs.-postcards REST is every bit as secure as SOAP. In particular REST can be carried over secure sockets (using the HTTPS protocol) and content can be encrypted using any mechanism you see fit. Without encryption REST and SOAP are both insecure; with proper encryption in place both are equally secure.
Ques 138. What do you know about AIDL?  
Ans.  AIDL stands for Android Interface Definition Language. It offers to define the client’s interface requirements and moreover a service in order to communicate at same level with the help of inter process communications.
Ques 139. What is ANR?  
Ans.  ANR stands for Application Not Responding a dialog that appears when an application doesn’t respond for more than 10 seconds. It shows the option of force closing the application.

Ques 140. What is the role of Orientation?  
Ans.  Orientation is used to determine the presentation of LinearLayout. It may be presented in rows or columns.
Ques 141. List the data types supported in AIDL?  
Ans.  AIDL supports string list map charSequence and all type of native java type data types.
Ques 142. What method does Android follow to track applications?  
Ans.  It is done by assigning each application with a unique ID (referred as Linux User ID).The question and answer section above is meant for a newbie to an experienced developer. Moreover these questions are also arranged by surveying the common question types in an interview which may help a candidate to prepare beforehand getting acquainted of some basic queries in relation to implied technology.

Ques 143.What is the upcoming version of Android OS?
Ans. Android M is the upcoming version for Android OS.

Ques 144. Describe some feature of upcoming version Android M?
Ans.
  • App permissions
  • Power Saving Doze mode
  • Apps Auto Backup
  • App Links
  • Fingerprint support
  • Mobile payments
  • RAM manager
  • Adoptable Storage Devices
  • Google Now
  •      Google Photos




For Android App Click Here.