Site icon C1CTech

Android Interview Questions

Given below is the list of most commonly asked Android Interview questions

1) What is Android?

Android is an open-source, Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablets but now it is also used in television,watch, game consoles, digital cameras, PCs and other electronics.

2) Explain Android application components.

Following is a list of components of Android application architecture:

3) What are the code names of android?

Version Code name API Level
1.5 Cupcake 3
1.6 Donut 4
2.1 Eclair 7
2.2 Froyo 8
2.3 Gingerbread 9 and 10
3.1 and 3.3 Honeycomb 12 and 13
4.0 Ice Cream Sandwitch 15
4.1, 4.2 and 4.3 Jelly Bean 16, 17 and 18
4.4 KitKat 19
5.0 Lollipop 21
6.0 Marshmallow 23
7.0 Nougat 24-25
8.0

9.0

Oreo

Pie

26-27

28

4) What are the advantages of Android?

Open-source : It means no license, distribution and development fee.

Platform-independent : It supports Windows, Mac, and Linux platforms.

Supports various technologies : It supports camera, Bluetooth, wifi etc. technologies.

Highly optimized Virtual Machine : Android uses a highly optimized virtual machine for mobile devices, called DVM (Dalvik Virtual Machine).

5) What are the core building blocks of android?

The core building blocks of Android are:

6) What is activity in Android?

An activity is the entry point for interacting with the user. It represents a single screen with a user interface.

7) What are the life cycle methods of android activity?

There are 7 life-cycle methods of activity. They are as follows:

8) What is intent?

An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a Background Service.  The primary pieces of information in an intent are:

9)Difference between implicit and explicit intent?

Explicit Intents

Explicit Intents are used to call a specific component. When you know which component you want to launch and you do not want to give the user free control over which component to use.

For example, you have an application that has 2 activities. Activity A and activity B. You want to launch activity B from activity A. In this case you define an explicit intent targeting activityB and then use it to directly call it.

Implicit Intents

Implicit Intents are used when you have an idea of what you want to do, but you do not know which component should be launched. Or if you want to give the user an option to choose between a list of components to use.

For example, you have an application that uses the camera to take photos. One of the features of your application is that you give the user the possibility to send the photos he has taken. You do not know what kind of application the user has that can send photos, and you also want to give the user an option to choose which external application to use if he has more than one. In this case you would not use an explicit intent. Instead you should use an implicit intent that has its action set to ACTION_SEND and its data extra set to the URI of the photo.

10) Explain the use of ‘bundle’ in android?

Bundles are generally used for passing data between various Android activities.

Pass data between activities by using Bundle and Intent objects.

Bundle b = new Bundle();
b.putString("myname", anystring);
Intent in = new Intent(getApplicationContext(), secondActivity.class);
in.putExtras(b);
startActivity(in);
//In the second activity, we have to access the data passed from the first activity
Intent in = getIntent();

//Now, you need to get the data from the bundle
Bundle b = in.getExtras();

//Finally, get the value of the string data associated with key named "myname"
String s = b.getString("myname");

11)What is Application?

The Application class in Android is the base class within an Android app that contains all other components such as activities and services. Application or its sub classes are instantiated before all the activities or any other application objects have been created in Android app.

12)What is Context?

Context is an Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

13) Describe content providers

A ContentProvider provides data from one application to another, when requested. It manages access to a structured set of data. It provides mechanisms for defining data security(i.e. by enforcing read/write permissions). ContentProvider offer a standard interface that connects data in one process with code running in another process.

When an application wants to access the data of a ContentProvider, it makes a request. These requests are handled by the ContentResolver object, which communicates with the ContentProvider as a client. The provider object receives data requests from clients, performs the requested action, and returns the results in cursor format.

14) How to access data using Content Provider?

1.To retrieve data from a provider, your application needs “read access permission” for the provider and must be defined in manifest.

2.Then, get access to the ContentResolver object by calling getContentResolver() on the Context object, and retrieving the data by constructing a query using ContentResolver.query().

3.The ContentResolver.query() method returns a Cursor, so you can retrieve data from each column using Cursor methods.

15) Describe services.

A Service is an application component that can perform long-running operations in the background, and it continues to run in the background even if the user switches to another application. These are the three different types of services:

16)Difference between service and thread?

Service: A service is simply a component that can run in the background, even when the user is not interacting with your application, so you should create a service only if that is what you need.

Thread: If you must perform work outside of your main thread, but only while the user is interacting with your application, you should instead create a new thread.

17) Difference between Service & Intent Service

18) Launch modes in Android?  

There are four different launch modes you can assign to the launchMode attribute:

 Suppose there is an activity stack of A -> B -> C.

Now if we launch B again with the launch mode as standard, the new stack will be A -> B -> C -> B.

CASE 1: 

Suppose there is an activity stack of A -> B.

Now if we launch C with the launch mode as singleTop, the new stack will be A -> B -> C as usual.

CASE 2: 

Now if there is an activity stack of A -> B -> C. 
If we launch C again with the launch mode as singleTop, the new stack will still be A -> B -> C.(Here old instance gets called and intent data route through onNewIntent() callback)

Suppose there is an activity stack of A -> B -> C
Now if we launch D with the launch mode as singleTask, the new stack will be A -> B -> C -> D as usual.

CASE 2:

Now if there is an activity stack of A -> B -> C -> D.
If we launch activity B again with the launch mode as singleTask, the new activity stack will be A -> B.

Activities C and D will be destroyed.

CASE 1:

Suppose there is an activity stack of A -> B -> C . If we launch activity D with the launch mode as singleInstance, the new activity stack will be: 
Task1 — A -> B -> C

Task2 — D (here D will be in different task)

CASE 2:

Suppose you have A, B, C activities in one task and activity D is in another task with “launch mode = singleInstance”. Now you again launching activity D-

State of Activity Stack before launch D

Task1 — A -> B -> C

Task2 — D

State of Activity Stack after launch D activity

Task1 — A -> B -> C

Task2 — D (Here old instance gets called and intent data route through onNewIntent() callback)

19) Mention two ways to clear the back stack of Activities when a new Activity is called using intent

The first approach is to use a FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NEW_TASK in conjunction.

The second way is by using FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK in conjunction.

20) What’s the difference between FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_CLEAR_TOP?

FLAG_ACTIVITY_CLEAR_TASK :

If set,this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.

FLAG_ACTIVITY_CLEAR_TOP :

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

This launch mode can also be used to good effect in conjunction with FLAG_ACTIVITY_NEW_TASK.

Hope you find this useful. This is just a list of questions I personally found useful in interviews.

Exit mobile version