Mindmajix

Android Interview Questions

Android Interview Questions

Q. What is Android?

It is an open-sourced operating system that is used primarily on mobile devices, such as cell phones and tablets. It is a Linux kernel-based system that’s been equipped with rich components that allows developers to create and run apps that can perform both basic and advanced functions.


Q. Who is the founder of Android?

Andy Rubin.


Q. What are the code names of android?

  1. Aestro
  2. Blender
  3. Cupcake
  4. Donut
  5. Eclair
  6. Froyo
  7. Gingerbread
  8. Honycomb
  9. Ice Cream Sandwitch
  10. Jelly Bean
  11. Kitkat
  12. Lollipop
  13. Marshmallow

Q. What are the advantages of android?

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

Platform-independent: It supports windows, mac and linux platforms.

Supports various technologies: It supports camera, bluetooth, wifi, speech, EDGE etc. technologies.

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


Q. Does android support other language than java?

Yes, android app can be developed in C/C++ also using android NDK (Native Development Kit). It makes the performance faster. It should be used with android SDK.


Q. What are the core building blocks of android?

The core building blocks of android are:

  • Activity
  • View
  • Intent
  • Service
  • Content Provider
  • Fragment etc.

Q. What is activity?

Activity is like a frame or window in java that represents GUI. It represents one screen of android.


Q. What are the life cycle methods of android activity?

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

  1. onCreate()
  2. onStart()
  3. onResume()
  4. onPause()
  5. onStop()
  6. onRestart()
  7. onDestroy()

Q. What is intent?

It is a kind of message or information that is passed to the components. It is used to launch an activity, display a web page, send sms, send email etc. There are two types of intents in android:

  1. Implicit Intent
  2. Explicit Intent

Q. What is implicit intent in android?

Implicit intent is used to invoke the system components.


Q. What is explicit intent in android?

Explicit intent is used to invoke the activity class.


Q. How to call another activity in android?

  1. Intent i = newIntent(getApplicationContext(), ActivityTwo.class);
  2. startActivity(i);

Q. What is service in android?

A service is a component that runs in the background. It is used to play music, handle network transaction etc.


Q. What is the name of database used in android?

SQLite: An opensource and lightweight relational database for mobile devices.


Q. What is AAPT?

AAPT is an acronym for android asset packaging tool. It handles the packaging process.


Q. What is content provider?

Content providers are used to share information between android applications.


Q. What is fragment?

Fragment is a part of Activity. By the help of fragments, we can display multiple screens on one activity.


Q. What is ADB?

ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator instance.


Q. What is NDK?

NDK stands for Native Development Kit. By using NDK, you can develop a part of app using native language such as C/C++ to boost the performance.


Q. What is ANR?

ANR stands for Application Not Responding. It is a dialog box that appears if the application is no longer responding.


Q. What Is the Google Android SDK?

The Google Android SDK is a toolset that developers need in order to write apps on Android enabled devices. It contains a graphical interface that emulates an Android driven handheld environment, allowing them to test and debug their codes.


Q. What is the Android Architecture?

Android Architecture is made up of 4 key components:

– Linux Kernel
– Libraries
– Android Framework
– Android Applications


Q. Describe the Android Framework.

The Android Framework is an important aspect of the Android Architecture. Here you can find all the classes and methods that developers would need in order to write applications on the Android environment.


Q. What is AAPT?

AAPT is short for Android Asset Packaging Tool. This tool provides developers with the ability to deal with zip-compatible archives, which includes creating, extracting as well as viewing its contents.


Q. What is the importance of having an emulator within the Android environment?

The emulator lets developers “play” around an interface that acts as if it were an actual mobile device. They can write and test codes, and even debug. Emulators are a safe place for testing codes especially if it is in the early design phase.


Q. What is the use of an activityCreator?

An activityCreator is the first step towards the creation of a new Android project. It is made up of a shell script that will be used to create new file system structure necessary for writing codes within the Android IDE.


Q. Describe Activities.

Activities are what you refer to as the window to a user interface. Just as you create windows in order to display output or to ask for an input in the form of dialog boxes, activities play the same role, though it may not always be in the form of a user interface.


Q. What are Intents?

Intents displays notification messages to the user from within the Android enabled device. It can be used to alert the user of a particular state that occurred. Users can be made to respond to intents.


Q. Differentiate Activities from Services.

Activities can be closed, or terminated anytime the user wishes. On the other hand, services are designed to run behind the scenes, and can act independently. Most services run continuously, regardless of whether there are certain or no activities being executed.


Q. What items are important in every Android project?

These are the essential items that are present each time an Android project is created:

– AndroidManifest.xml
– build.xml
– bin/
– src/
– res/
– assets/


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 is Orientation?

Orientation, which can be set using setOrientation(), dictates if the LinearLayout is represented as a row or as a column. Values are set as either HORIZONTAL or VERTICAL.


Q. What is the importance of Android in the mobile market?

Developers can write and register apps that will specifically run under the Android environment. This means that every mobile device that is Android enabled will be able to support and run these apps. With the growing popularity of Android mobile devices, developers can take advantage of this trend by creating and uploading their apps on the Android Market for distribution to anyone who wants to download it.


Q. What do you think are some disadvantages of Android?

Given that Android is an open-source platform, and the fact that different Android operating systems have been released on different mobile devices, there’s no clear cut policy to how applications can adapt with various OS versions and upgrades. One app that runs on this particular version of Android OS may or may not run on another version. Another disadvantage is that since mobile devices such as phones and tabs come in different sizes and forms, it poses a challenge for developers to create apps that can adjust correctly to the right screen size and other varying features and specs.


Q. What is adb?

Adb is short for Android Debug Bridge. It allows developers the power to execute remote shell commands. Its basic function is to allow and control communication towards and from the emulator port.


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 ANR?

ANR is short for Application Not Responding. This is actually a dialog that appears to the user whenever an application have been unresponsive for a long period of time.


Q. Which elements can occur only once and must be present?

Among the different elements, the and elements must be present and can occur only once. The rest are optional, and can occur as many times as needed.


Q. How are escape characters used as attribute?

Escape characters are preceded by double backslashes. For example, a newline character is created using ‘\\n’


Q. What is the importance of settings permissions in app development?

Permissions allow certain restrictions to be imposed primarily to protect data and code. Without these, codes could be compromised, resulting to defects in functionality.


Q. What is the function of an intent filter?

Because every component needs to indicate which intents they can respond to, intent filters are used to filter out intents that these components are willing to receive. One or more intent filters are possible, depending on the services and activities that is going to make use of it.


Q. Enumerate the three key loops when monitoring an activity

– Entire lifetime – activity happens between onCreate and onDestroy
– Visible lifetime – activity happens between onStart and onStop
– Foreground lifetime – activity happens between onResume and onPause


Q. When is the onStop() method invoked?

A call to onStop method happens when an activity is no longer visible to the user, either because another activity has taken over or if in front of that activity.


Q. Is there a case wherein other qualifiers in multiple resources take precedence over locale?

Yes, there are actually instances wherein some qualifiers can take precedence over locale. There are two known exceptions, which are the MCC (mobile country code) and MNC (mobile network code) qualifiers.


Q. What are the different states wherein a process is based?

There are 4 possible states:

– foreground activity
– visible activity
– background activity
– empty process


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. What role does Dalvik play in Android development?

Dalvik serves as a virtual machine, and it is where every Android application runs. Through Dalvik, a device is able to execute multiple virtual machines efficiently through better memory management.


Q. What is the AndroidManifest.xml?

This file is essential in every application. It is declared in the root directory and contains information about the application that the Android system must know before the codes can be executed.


Q. What is the proper way of setting up an Android-powered device for app development?

The following are steps to be followed prior to actual application development in an Android-powered device:

– Declare your application as “debuggable” in your Android Manifest.
– Turn on “USB Debugging” on your device.
– Set up your system to detect your device.


Q. Enumerate the steps in creating a bounded service through AIDL.

  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 is the importance of Default Resources?

When default resources, which contain default strings and files, are not present, an error will occur and the app will not run. Resources are placed in specially named subdirectories under the project res/ directory.


Q. When dealing with multiple resources, which one takes precedence?

Assuming that all of these multiple resources are able to match the configuration of a device, the ‘locale’ qualifier almost always takes the highest precedence over the others.


Q. When does ANR occur?

The ANR dialog is displayed to the user based on two possible conditions. One is when there is no response to an input event within 5 seconds, and the other is when a broadcast receiver is not done executing within 10 seconds.


Q. What is AIDL?

AIDL, or Android Interface Definition Language, handles the interface requirements between a client and a service so both can communicate at the same level through interprocess communication or IPC. This process involves breaking down objects into primitives that Android can understand. This part is required simply because a process cannot access the memory of the other process.


Q. What data types are supported by AIDL?

AIDL has support for the following data types:

-string
-charSequence
-List
-Map
-all native Java data types like int,long, char and Boolean


Q. What is a Fragment?

A fragment is a part or portion of an activity. It is modular in a sense that you can move around or combine with other fragments in a single activity. Fragments are also reusable.


Q. What is a visible activity?

A visible activity is one that sits behind a foreground dialog. It is actually visible to the user, but not necessarily being in the foreground itself.


Q. When is the best time to kill a foreground activity?

The foreground activity, being the most important among the other states, is only killed or terminated as a last resort, especially if it is already consuming too much memory. When a memory paging state has been reach by a foreground activity, then it is killed so that the user interface can retain its responsiveness to the user.


Q. Is it possible to use or add a fragment without using a user interface?

Yes, it is possible to do that, such as when you want to create a background behavior for a particular activity. You can do this by using add(Fragment,string) method to add a fragment from the activity.


Q. How do you remove icons and widgets from the main screen of the Android device?

To remove an icon or shortcut, press and hold that icon. You then drag it downwards to the lower part of the screen where a remove button appears.


Q. What are the core components under the Android application architecture?

There are 5 key components under the Android application architecture:

– services
– intent
– resource externalization
– notifications
– content providers


Q. What composes a typical Android application project?

A project under Android development, upon compilation, becomes an .apk file. This apk file format is actually made up of the AndroidManifest.xml file, application code, resource files, and other related files.


Q. What is a Sticky Intent?

A Sticky Intent is a broadcast from sendStickyBroadcast() method such that the intent floats around even after the broadcast, allowing others to collect data from it.


Q. Do all mobile phones support the latest Android operating system?

Some Android-powered phone allows you to upgrade to the higher Android operating system version. However, not all upgrades would allow you to get the latest version. It depends largely on the capability and specs of the phone, whether it can support the newer features available under the latest Android version.


Q. What is portable wi-fi hotspot?

Portable Wi-Fi Hotspot allows you to share your mobile internet connection to other wireless device. For example, using your Android-powered phone as a Wi-Fi Hotspot, you can use your laptop to connect to the Internet using that access point.


Q. What is an action?

In Android development, an action is what the intent sender wants to do or expected to get as a response. Most application functionality is based on the intended action.


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. What language is supported by Android for application development?

The main language supported is Java programming language. Java is the most popular language for app development, which makes it ideal even for new Android developers to quickly learn to create and deploy applications in the Android environment.


Q. When does onResume() method called?

onResume() method is an activity lifecycle method. This is called when the activity come to foreground. You can override this method in your activity to execute code when activity is started, restarted or comes to foreground.


Q. How to launch an activity in your application?

For launching an activity, we need to create an explicit intent that defines the activity that we wish to start. In the below code snippet, the first parameter to Intent constructor is the current activity context and the second parameter is your new activity class.startActivity() method can be called on Activity context.

Intent intent = new Intent(this, SecondActivity.class);

startActivity(intent);

If you want to start an activity from fragment

Intent intent = new Intent(getActivity(), SecondActivity.class);

getActivity().startActivity(intent);


Q. How to define an Activity as launcher activity in application Manifest file?

All the activities used in the application should be defined in application manifest file. For launcher activity you need to define intent filter as shown in the below code snippets.

<activity android:name=”.MyActivity”

android:label=”@string/app_name”>

<intent-filter>

<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />

</intent-filter>

</activity>


Q. What is a ANR ?

ANR is short for Application Not Responding. Android systems shows this dialog, if application is performing too much of task on main thread and been unresponsive for a long period of time.


Q. What are the measures to avoid application ANR?

ANR in application is annoying to user. It can be caused due to various reasons. Below are some of the tips to avoid ANR

  • Perform all you long running network or database operation in separate thread
  • If you have too much of background tasks, then take it off the UI thread. You may use IntentService
  • Server not responding for longer period can be guilt for ANR. To avoid always define HTTP time out for your all your webs service calls.
  • Be watchful of infinite loops during your complex calculations

Q. What is the difference between a regular .png and a nine-patch image?

The nine patch images are extension with .9.png. 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 to share text using android share Intent ?

Share intent is an easy and convenient way of sharing content of your application with other apps.

Intent sendIntent = new Intent();

sendIntent.setAction(Intent.ACTION_SEND);

sendIntent.putExtra(Intent.EXTRA_TEXT, “This is my text to send.”);

sendIntent.setType(“text/plain”);

startActivity(sendIntent);


Q. What is the use of WebView in android?

A WebView is an android UI component that displays webpages. It can either display a remote webpage or can also load static HTML data. This encompasses the functionality of a browser that can be integrated to application. WebView uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, etc.


Q. Define different kind of context in android

Context defines the current state of application or object. Context provides access to things such as creating new activity instance, access databases, start a service, etc. You can get the context by invoking getApplicationContext(),getContext(), getBaseContext() or this when in the activity class.

//Creating ui instance

ImageButton button = new ImageButton(getContext());

//creating adapter

ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), …);

//querying content provider

getApplicationContext().getContentResolver().query(uri, …);

//start activity. Here this means activity context

Intent intent = new Intent(this, SecondActivity.class);


Q. What are the different storage methods in android

Android offers several different options for data persistence.

  1. Shared Preferences– Store private primitive data in key-value pairs. This sometimes gets limited as it offers only key value pairs. You cannot save your own java types.
  2. Internal Storage– Store private data on the device memory
  3. External Storage– Store public data on the shared external storage
  4. SQLite Databases– Store structured data in a private database. You can define many number of tables and can store data like other RDBMS.

Q. How to declare an activity in the manifest?

In order to declare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example::

<manifest … >

<application … >

<activity android:name=”.ExampleActivity” />

</application … >

</manifest >


Q. How can an activity include intent filters?

An activity can include intent filter like this:

<activity android:name=”.ExampleActivity” android:icon=”@drawable/app_icon”>

<intent-filter>

<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />

</intent-filter>

</activity>


Q. How to start an activity?

Activity can be started as:

Intent intent = new Intent(this, SignInActivity.class);

startActivity(intent);


Q. How can a user send an email message with the intent? Explain with an example.

 Example is as under:

Intent intent = new Intent(Intent.ACTION_SEND);

intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);

startActivity(intent);


Q. How to start an activity for a result?

Sometimes we need to start an activity for a result. An example is given below:

private void pickContact() {

// Create an intent to “pick” a contact, as defined by the content provider URI

Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);

startActivityForResult(intent, PICK_CONTACT_REQUEST);

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

// If the request went well (OK) and the request was PICK_CONTACT_REQUEST

if (resultCode == Activity.RESULT_OK && requestCode == PICK_CONTACT_REQUEST) {

// Perform a query to the contact’s content provider for the contact’s name

Cursor cursor = getContentResolver().query(data.getData(),

new String[] {Contacts.DISPLAY_NAME}, null, null, null);

if (cursor.moveToFirst()) { // True if the cursor is not empty

int columnIndex = cursor.getColumnIndex(Contacts.DISPLAY_NAME);

String name = cursor.getString(columnIndex);

// Do something with the selected contact’s name…

}

}

}


Q. How to shut Down an Activity?

 There can be two different ways to do so. By calling its finish() method and also by finishActivity().


Q. In how many different states can an activity exist?

There are three different states in which an activity can exist. Resumed, Paused and Stopped.


Q. How to implement the lifecycle callbacks?

 Lifecycle callbacks can be implemented as:

public class ExampleActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// The activity is being created.

}

@Override

protected void onStart() {

super.onStart();

// The activity is about to become visible.

}

@Override

protected void onResume() {

super.onResume();

// The activity has become visible (it is now “resumed”).

}

@Override

protected void onPause() {

super.onPause();

// Another activity is taking focus (this activity is about to be “paused”).

}

@Override

protected void onStop() {

super.onStop();

// The activity is no longer visible (it is now “stopped”)

}

@Override

protected void onDestroy() {

super.onDestroy();

// The activity is about to be destroyed.

}

}


Q. When does entire lifetime of an activity happen?

It happens between the call to onCreate() and the call to onDestroy().


Q. When does visible lifetime of an activity happen?

It happens between the call to onStart() and the call to onStop().


Q. When does foreground lifetime of an activity happen?

 It happens between the call to onResume() and the call to onPause().


Q. What is a Fragment?

The fragment can be best explained as a behavior or a portion of user interface in an Activity.


Q. Give an example of a fragment.

 Example is as under:

public static class ExampleFragment extends Fragment {

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

// Inflate the layout for this fragment

return inflater.inflate(R.layout.example_fragment, container, false);

}

}


Q. How to add a fragment to an activity?

 <?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”

android:orientation=”horizontal”

android:layout_width=”match_parent”

android:layout_height=”match_parent”>

<fragment android:name=”com.example.news.ArticleListFragment”

android:id=”@+id/list”

android:layout_weight=”1″

android:layout_width=”0dp”

android:layout_height=”match_parent” />

<fragment android:name=”com.example.news.ArticleReaderFragment”

android:id=”@+id/viewer”

android:layout_weight=”2″

android:layout_width=”0dp”

android:layout_height=”match_parent” />

</LinearLayout>


Q. How one can acquire an instance of FragmentTransaction from the FragmentManager?

An example to acquire an instance of FragmentTransaction is given below:

FragmentManager fragmentManager = getFragmentManager();

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();


Q. How to create new fragment and transaction?

 Do the following:

Fragment newFragment = new ExampleFragment();

FragmentTransaction transaction = getFragmentManager().beginTransaction();


Q. How to add a transaction to the back stack?

The following code snippet shows how to add a transaction to the back stack:

transaction.replace(R.id.fragment_container, newFragment);

transaction.addToBackStack(null);


Q. How to commit a transaction?

 A transaction is committed using commit method on transaction object.

transaction.commit();


Q. What are the characteristics of Loaders?

 The characteristics are as under:

  1. a) There is no need for them to re-query their data.
  2. b) Asynchronous loading of data is provided by them.
  3. c) Usually available to every Activity and Fragment.

Q. How to start a Loader?

 Use the following:

getLoaderManager().initLoader(0, null, this);


Q. How to restart a Loader?

 Do the following:

public boolean onQueryTextChanged(String newText) {

// Called when the action bar search text has changed. Update

// the search filter, and restart the loader to do a new query

// with this filter.

mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;

getLoaderManager().restartLoader(0, null, this);

return true;

}


Q. What is the purpose of Loaders?

 The main purpose of loaders is to make it easy to asynchronously load data in an activity or fragment.


Q. How to declare a service in the manifest?

 Use the following:

<manifest … >

<application … >

<service android:name=”.ExampleService” />

</application>

</manifest>


Q. Give an example of implementation of IntentService.

 Use the following:

public class HelloIntentService extends IntentService {

/**

* A constructor is required, and must call the super IntentService(String)

* constructor with a name for the worker thread.

*/

public HelloIntentService() {

super(“HelloIntentService”);

}

/**

* The IntentService calls this method from the default worker thread with

* the intent that started the service. When this method returns, IntentService

* stops the service, as appropriate.

*/

@Override

protected void onHandleIntent(Intent intent) {

// Normally we would do some work here, like download a file.

// For our sample, we just sleep for 5 seconds.

long endTime = System.currentTimeMillis() + 5*1000;

while (System.currentTimeMillis() < endTime) {

synchronized (this) {

try {

wait(endTime – System.currentTimeMillis());

} catch (Exception e) {

}

}

}

}


0 Responses on Android Interview Questions"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.