Android Questions & Answers for Experienced

Q. What is assert? Where will you use it?

– Assertion is a statement in java. It can be used to test your assumptions about the program. While executing assertion, it is believed to be true. If it fails, JVM will throw an error named AssertionError. It is mainly used for testing purpose.
for Example
assert value>=18:” Not valid”;
Q. How do you find memory leaks in android application?

– There are lots of classes and components who are responsible for application memory leaking :-
* static classes- if you are using static classes into your apps and do not clearing their instance than m/m is leaking
* static view -also leaking m/m in our apps
* Inner classes its also same like static classes .
* anonymous class
* Handler -handler also responsible for m/m leaking if you are not using in proper way.
* Thread ,Task & Timer Tasks
* Sensors
* Services and Intent services
Q. What is the difference between this and getapplicationcontext?

– this pointer always points to current class object,app context will point to entire process. there is only one app context .if you want to use some control whose life
time is through out your application life time then go for app context, else use this pointer
Q. What are the type of flags to run an application in android?


How to update UI from a service in android?

There are many ways we can update UI from service :

* Use a dynamic broadcast receiver in the activity, and send a broadcast from the service. Once the dynamic receiver is triggered update UI from that receiver.

* By using runOnUIThread() we can also update UI from service, but its not a good practice.

* Use thread with handler so that we can able to communicate with background thread to UI thread and update it
Q. What is sleep mode in android?

Sleep mode mean CPU will be sleeping and it doesn’t accept any commands from android device except Radio interface layer and alarm.
Q. What is the difference between sleep() and wait()methods?

sleep() is a static method on thread class method it makes the current thread into non-runnable state for specificed amount of time. During this time, thread keeps
the locks(monitors) it has acquired.

wait() is a method on Object class. it makes the current thread into non-runnable state. Wait is called on a object. before calling wait() method ,the object should be synchronized, Means
the object should be inside synchronized block.The call to wait() releases the acquired lock. for invoke the current thread we have to call notify() or notifyAll() method after wait().
Q. What is singleton class in android?

A class which can create only an object, that object can be share able to all other classes.
class MySingleTon{
//class reference
public static MySingleTon mSingleTon;
//for making singleton constructor should be private
private MySingleTon(){}
// initiating reference of class
static {
mSingleTon=new MySingleTon();
//create method who can always give you class instance everytime
pub static MySingleTon getInstance(){
return mSingleTon;

Q.How to change application name after its deployment?

It’s not truly recommended to change application name after it’s deployment, if we change, it will impact on all other internal components.
Q.What is a Sticky Intent in android?

Sticky Intent is also a type of intent which allows the communication between a function and a service for example,sendStickyBroadcast() is perform the operations after completion of intent also.
Q.What are the different storages available in android?

Shared Preferences

* Internal Storage

* External Storage

* SQLite Databases

* Network Connection
Q.What are the exceptions available in android?

There are lots of exceptions in android like :
InflateException, Surface.OutOfResourceException, SurfaceHolder.BadSurfaceTypeException, WindowManager.BadTokenException ,Activity not found exceptions and etc…
Q.What is Intent-filters

Intent-filter is an expression in an app’s manifest file that specifies that specifies the type of intents that the component would like to receive

when you create implicit intent , the android system finds the appropriate component to start by comparing the contents of the intent to the intent-filters declared in the manifest file of other apps on the device
if the intent matches an intent-filter, the system starts that component and delivers it the intent object.

<activity android:name=”.HelloWorld” android:label=”@string/app_name”>
<action android:name=”android.intent.action.VIEW”>
<category android:name=”android.intent.category.DEFAULT”>
<category android:name=”android.intent.category.BROWSABLE”>
<data android:scheme=”http” android:host=””>
Launch HelloWorld
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse(“”));

Q.What are the notifications available in android?

Toast Notification – It will show a pop up message on the surface of the window

Status Bar Notification – It will show notifications on status bar

Dialogue Notification – It is an activity related notification.
Q. Advance Features of Android OS?

Google now (voice assistant)
* NFC (Near Field Communication)
* Unlock your phone by your face
* Use your phone with joystick to enjoy gaming experience
* Connect your phone with LED TV via MHL or micro HDMI cable
* Screen Capture
* Multitasking Future (Task Switcher)
* Data Usages (Check and also set limit from device)
Q.What’s the difference between a file, a class and an activity in android?

File – It is a block of arbitrary information, or resource for storing information. It can be of any type.

Class – Its a compiled form of .Java file . Android finally used this .class files to produce an executable apk

Activity – An activity is the equivalent of a Frame/Window in GUI toolkits. It is not a file or a file type it is just a class that can be extended in Android for loading UI elements on view.
Q.What is the importance of XML-based layouts?

The use of XML-based layouts provides a consistent and somewhat standard means of setting GUI definition format. In common practice, layout details are placed in XML files
while other items are placed in source files.
Q.What are containers?

Containers, as the name itself implies, holds objects and widgets together, depending on which specific items are needed and in what particular arrangement that is wanted. Containers may hold labels,
fields, buttons, or even child containers, as examples.
Q.What are the four essential states of an activity?

Active – if the activity is at the foreground.
Paused – if the activity is at the background and still visible.
Stopped – if the activity is not visible and therefore is hidden or obscured by another activity.
Destroyed – when the activity process is killed or completed terminated.
Q.What is AIDL in android ? & What are the steps in creating a bounded service through AIDL.

AIDL stands for android interface definition language which is basically used for Inter process communication between client and server

For creating .aidl file :
1. create the .aidl file, which defines the programming interface

2. implement the interface, which involves extending the inner abstract Stub class as well as implanting its methods.

3. expose the interface, which involves implementing the service to the clients.
Q.What data types are supported by AIDL?

AIDL has support for the following data types:

all native Java data types like int, long, char and Boolean
Q.What is the difference between a regular bitmap and a nine-patch image?

In general, a Nine-patch image allows resizing that can be used as background or other image size requirements for the target device. The Nine-patch refers to the way you can resize the image: 4 corners that are unscaled,
4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.
Q.How can the ANR be prevented?

One technique that prevents the Android system from concluding a code that has been responsive for a long period of time is to create a child thread. Within the child thread, most of the actual workings of the codes can be placed,
so that the main thread runs with minimal periods of unresponsive times.
Q.Difference between Aysntask and IntentService

Both are abstract classes of android used to perform background tasks.but the main difference is that by using AsyncTask we can update UI without using
any other class or component but it can’t be done by IntentService.

If we are using IntentService than we dont need to worry about simultaneous hits ,because it auto create internal queue and handle asynchronous hits but have to worry about for AsyncTask.
Q.What’s the difference between Parcelable and Serializable?

Serializable is a java specific and Parcelable is android specific class.

Serializable is a marker interface so by implementing this interface we can serialize whole class

but By using Parcelable interface we can serialize particular piece of code it gives two method writeToParcable() & writeToParcable().