Pages

Saturday, 27 September 2014

Android Interview Questions For Fresher and Experience

1. What are the key components of Android Architecture?


Android Architecture consists of 4 key components:
- Linux Kernel
- Libraries
- Android Framework
- Android Applications

2. What are the advantages of having an emulator within the Android environment?

- The emulator allows the developers to work around an interface which acts as if it were an actual mobile device.
- They can write, test and debug the code.
- They are safe for testing the code in early design phase

3. Tell us something about activityCreator?

- An activityCreator is the initial step for creation of a new Android project.
- It consists of a shell script that is used to create new file system structure required for writing codes in Android IDE.

4. What do you know about Intents?

- Notification messages to the user from an Android enabled device can be displayed using Intents. The users can respond to intents.
- There are two types of Intents - Explicit Intent, Implicit Intent.

5. What is an Explicit Intent?

- Explicit intent specifies the particular activity that should respond to the intent.
- They are used for application internal messages.

6. What is an Implicit Intent?

- In case of Implicit Intent, an intent is just declared.
- It is for the platform to find an activity that can respond to it.
- Since the target component is not declared, it is used for activating components of other applications.


7. What do intent filters do?

- There can be more than one intents, depending on the services and activities that are going to use them.
- Each component needs to tell which intents they want to respond to.
- Intent filters filter out the intents that these components are willing to respond to.

8. Where are lay out details placed? Why?

- Layout details are placed in XML files
- XML-based layouts provide a consistent and standard means of setting GUI definition format.

9. What do containers hold?

- Containers hold objects and widgets in a specified arrangement.
- They can also hold labels, fields, buttons, or child containers. .

10. What is Orientation?

- Orientation decides if the LinearLayout should be presented in row wise or column wise fashion.
- The values are set using setOrientation()
- The values can be HORIZONTAL or VERTICAL

11. What is it important to set permissions in app development?

- Certain restrictions to protect data and code can be set using permissions.
- In absence of these permissions, codes could get compromised causing defects in functionality.

12. What is AIDL?

- AIDL is the abbreviation for Android Interface Definition Language.
- It handles the interface requirements between a client and a service to communicate at the same level through interprocess communication.
- The process involves breaking down objects into primitives that are Android understandable.

13. What data types are supported by AIDL?

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

14. Tell us something about nine-patch image.

- The Nine-patch in the image name refers to the way the image can be resized: 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.
- A Nine-patch image allows resizing that can be used as background or other image size requirements for the target device.

15. Which dialog boxes are supported by android?

Android supports 4 dialog boxes:

a.) AlertDialog: Alert dialog box supports 0 to 3 buttons and a list of selectable elements which includes check boxes and radio buttons.

b.) ProgressDialog: This dialog box is an extension of AlertDialog and supports adding buttons. It displays a progress wheel or bar.

c.) DatePickerDialog: The user can select the date using this dialog box.

d.) TimePickerDialog: The user can select the time using this dialog box.
16. What is Dalvik Virtual Machine?
- It is Android's virtual machine.
- It is an interpreter-only virtual machine which executes files in Dalvik Executable (.dex) format. This format is optimized for efficient storage and memory-mappable execution.

17. Explain in brief about the important file and folder when you create new android application.
When you create android application the following folders are created in the package explorer in eclipse which are as follows:

src: Contains the .java source files for your project. You write the code for your application in this file. This file is available under the package name for your project.
gen —This folder contains the R.java file. It is compiler-generated file that references all the resources found in your project. You should not modify this file.
Android 4.0 library: This folder contains android.jar file, which contains all the class libraries needed for an Android application.
assets: This folder contains all the information about HTML file, text files, databases, etc.
bin: It contains the .apk file (Android Package) that is generated by the ADT during the build process. An .apk file is the application binary file. It contains everything needed to run an Android application.
res: This folder contains all the resource file that is used byandroid application. It contains subfolders as: drawable, menu, layout, and values etc.

18. Explain AndroidManifest.xmlfile in detail.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.careerride" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name="com.example.careerride.MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
The AndroidManifest.xml file contains the following information about the application:
  • It contains the package name of the application.
  • The version code of the application is 1.This value is used to identify the version number of your application.
  • The version name of the application is 1.0
  • The android:minSdkVersion attribute of the element defines the minimum version of the OS on      which the application will run.
  • ic_launcher.png is the default image that located in the drawable folders.
  • app_name defines the name of applicationand available in the strings.xml file.
  • It also contains the information about the activity. Its name is same as the application name.
19. Describe android Activities in brief.

Activity provides the user interface. When you create an android application in eclipse through the wizard it asks you the name of the activity. Default name is MainActivity. You can provide any name according to the need. Basically it is a class (MainActivity) that is inherited automatically from Activity class. Mostly, applications have oneor more activities; and the main purpose of an activity is to interact with the user. Activity goes through a numberof stages, known as an activity’s life cycle.
Example:
packagecom.example.careerride; //Application name careerride

importandroid.os.Bundle; // Default packages
importandroid.app.Activity; // Default packages
importandroid.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
When you run the application onCreate method is called automatically.

20. Describe Intents in detail.

An Android application can contain zero or more activities. If you want to navigate fromone activity to another then android provides you Intent class. This class is available inandroid.content.Intent package.One of the most common uses for Intents is to start new activities.
There are two types of Intents.
Explicit Intents
Implicit Intents
Intents works in pairs: actionand data. The action defines what you want to do, such as editing an item, viewingthe content of an item etc. The dataspecifies what is affected,such as a person in the Contacts database. The data is specified as anUri object.
Explicitly starting an Activity
Intent intent = newIntent (this, SecondActivity.class);
startActivity(intent);
Here SecondActivity is the name of the target activity that you want to start.
Implicitly starting an Activity
If you want to view a web page with the specified URL then you can use this procedure.
Intent i = newIntent(android.content.Intent.ACTION_VIEW,Uri.parse(“http://www.amazon.com”));
startActivity(i);
if you want to dial a telephone number then you can use this method by passing the telephone number in the data portion
Intent i = newIntent (android.content.Intent.ACTION_DIAL,Uri.parse(“tel:+9923.....”));
startActivity(i);
In the above method the user must press the dial button to dial the number. If you want to directly call the number without user intervention, change the action as follows:
Intent i = newIntent (android.content.Intent.ACTION_CALL,Uri.parse(“tel:+9923.....”));
startActivity(i);
If you want to dial tel no or use internet then write these line in AndroidManifest.xml
<uses-permissionandroid:name=”android.permission.CALL_PHONE”/>
<uses-permissionandroid:name=”android.permission.INTERNET”/>

21. How to send SMS in android? Explain with example.

SMS messaging is one of the basic and important applications on a mobile phone. Now days every mobile phone has SMS messaging capabilities, and nearly all users of any age know how to send and receive suchmessages. Mobile phones come with a built-in SMS application that enables you to send and receiveSMS messages. If you want to send the SMS programmatically then follow the following steps.
Sending SMS Messages Programmatically
Take a button on activity_main.xml file as follows.
<Button android:id="@+id/btnSendSMS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:onClick=”sendmySMS” android:text="sendSMS" />
According to above code when user clicks the button sendmySMS method will be called. sendmySMS is user defined method.
In the AndroidManifest.xml file, add the following statements
<uses-permissionandroid:name=”android.permission.SEND_SMS”/>
Now we write the final step. Write the given below method in MainActivity,java file
publicvoidsendmySMS(View v)
{
SmsManagersms = SmsManager.getDefault();
sms.sendTextMessage("5556", null, "Hello from careerRide", null, null);
}
In this example I have used two emulator. On the first Android emulator (5554), click the Send SMSbutton to send an SMS message to the second emulator(5556).

22. Describe the SmsManager class in android.


SmsManager class is responsible for sending SMS from one emulator to another or device.
You cannot directly instantiate this class; instead, you call the getDefault() static method to obtain an SmsManager object. You then send the SMS message using the sendTextMessage() method:
SmsManagersms = SmsManager.getDefault();
sms.sendTextMessage("5556", null, "Hello from careerRide", null, null);
sendTextMessage() method takes five argument.
  • destinationAddress — Phone number of the recipient.
  • scAddress — Service center address; you can use null also.
  • text — Content of the SMS message that you want to send.
  • sentIntent — Pending intent to invoke when the message is sent.
  • deliveryIntent — Pending intent to invoke when the message has been delivered.
23. How you can use built-in Messaging within your application?

You can use an Intent object to activate the built-in Messaging service. You have to pass MIME type “vnd.android-dir/mms-sms”, in setType method of Intent as shown in the following given below code.
Intent intent = new Intent (android.content.Intent.ACTION_VIEW);
intent.putExtra("address", "5556; 5558;");// Send the message to multiple recipient.
itent.putExtra("sms_body", "Hello my friends!");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
What are different data storage options are available in Android?
Different data storage options are available in Android are:
  • SharedPreferences
  • SQlite
  • ContentProvider
  • File Storage
  • Cloud Storage
24. Describe SharedPreference storage option with example.

SharedPreference is the simplest mechanism to store the data in android. You do not worry about creating the file or using files API.It stores the data in XML files. SharedPreference stores the data in key value pair.The SharedPreferences class allows you to save and retrieve key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: boolean, floats, int, longs, and strings.The data is stored in XML file in the directory data/data//shared-prefs folder.
Application of SharedPreference
  • Storing the information about number of visitors (counter).
  • Storing the date and time (when your Application is updated).
  • Storing the username and password.
  • Storing the user settings.
Example:





For storing the data we will write the following code in main activity on save button:
SharedPreferences sf=getSharedPreferences("MyData", MODE_PRIVATE);
SharedPreferences.Editored= sf.edit();
ed.putString("name", txtusername.getText().toString());
ed.putString("pass", txtpassword.getText().toString());
ed.commit();
In this example I have taken two activities. The first is MainActivity and the second one is SecondActivity.When user click on save button the user name and password that you have entered in textboxes, will be stored in MyData.xml file.
Here MyData is the name of XML file .It will be created automatically for you.

MODE_PRIVATE means this file is used by your application only.
txtusernameand txtpassword are two EditText control in MainActivity.
For retrieving the data we will write the following code in SecondActiviy when user click on Load button:
Public static final String DEFAULT=”N? A”;
DEFAULT is a String type user defined global variable.If the data is not saved in XML file and user click on load button then your application will not give the error. It will show message “No Data is found”. Here name and pass are same variable that I have used in MainActivity.
SharedPreferences sf=getSharedPreferences("MyData", Context.MODE_PRIVATE);
String Uname=sf.getString("name", DEFAULT);
String UPass=sf.getString("pass", DEFAULT);
if(name.equals(DEFAULT)||Pass.equals(DEFAULT))
{
Toast.makeText(this, "No data is found", Toast.LENGTH_LONG).show();
}
else
{
Txtusername.setText(Uname);
Txtpassword.setText(UPass) ;
}

25.  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.


26. 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.

27. What is the Android Architecture?
--  Android Architecture is made up of 4 key components:
- Linux Kernel
- Libraries
- Android Framework
- Android Applications

28.  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.

29. 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.

30.  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.

31. 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.

32. 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.

33. 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.

34. 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.
35.  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/

36. 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.

37. 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.

38. 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.

39. 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.

40. 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.

41. 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.

42. 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

43. 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.

44. 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.
45.  How are escape characters used as attribute?
 Escape characters are preceded by double backslashes. For example, a newline character is created using ‘\\n’

47. 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.

48. 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.

49. 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

50.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.

51.  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.

52. What are the different states wherein a process is based?
There are 4 possible states:
- foreground activity
- visible activity
- background activity
- empty process

53. 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.

54. 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.

55. 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.

57. 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.

58. 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.

59. 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.

60. 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.

61. 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.

62. 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.

63. 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

64. 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.

65. 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.

66. 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.

67. 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.

68. 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.

69  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

70.  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.

71. 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.

72. 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.


73.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.

74.  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.

75. 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.

76. 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.