Android interview questions and answers - freshers, experienced

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 by android application. It contains subfolders as: drawable, menu, layout, and values etc.

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.

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.

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.

1) Explicit Intents
2) 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”/>

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 such messages. Mobile phones come with a built-in SMS application that enables you to send and receive SMS 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).

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.

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

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) ;
}

What are the key components of Android Architecture?

Android Architecture consists of 4 key components:

- Linux Kernel
- Libraries
- Android Framework
- Android Applications
1 2 3 4 5

What is android? What are the features of Android?
What is android? - Android is a stack of software for mobile devices which has Operating System, middleware and some key applications.....
Why to use Android?
Why to use Android? - Android is useful because:...
Android Application Architecture
Android Application Architecture - Android Application Architecture has the following components:....
Post your comment
Discussion Board
What is URI and Order of dialog box button?
URI extends for Uniform Resource Identifier.

Order of buttons on dialog box?

Positive, Neutral, Negative.

check more: http://www.coders-hub.com
Md Mohsin 02-27-2015
Question about android
can any body tell me about these things
background service,intents,broadcast receiver,Content provider.
Anadoir Devloper 02-18-2015
XML parsing in Android
How one can parse XML in android?-
As I have get some knowledge from-" http://techlovejump.com/xml-parsing-android-tutorial-example/".
suranjan kumar 11-29-2014
android interview qa
I need more adevise from androidinterview qa .
martini 08-25-2014
Wants to help someone that need it.
Hey friends you can find the more@..............http://androidtutorialsrkt.blogspot.in/
robi kumar tomer 11-7-2013
Android interview questions and answers.
How to avoid ANR status?
Android allows the system to protect the applications that are not responsive for a period of time by displaying a status called as ANR (Application not responding). Methods should use the main thread for work, as it takes long time for the main thread to complete the task. The work should be divided and another thread named as child thread be used for executing more tasks, as it takes less time. Main thread should provide a handler for child threads to post back upon completion.

What is the file features used in android?
Android is rich in file features and it provides lots of variations in them as well. The file features are as follows:
Intent filters: includes bundle of information which describes a desired action.

Icons and Labels: includes information for small icon and a text label that can be displayed to users. These are set for an intent filter and are used to represent a component which fulfills the function advertised by the filter.

Permissions: it is a restriction or limitation access to a part of code or data on the device. It is given as:-android.permission.CALL_EMERGENCY_NUMBERS

Libraries: it includes the basic packages for building and developing applications.
Rohit Sharma 12-11-2011
Android interview questions and answers.
How does the AOSP relate to the Android Compatibility Program?

AOSP stands for Android Open-source project that maintains Android software and keep track of the new versions. It can be used for any purpose including the devices that are not compatible with other devices. It is related to the Android Compatibility Program as it defines the implementation of Android that is compatible with the third party apps.

What are the different Storage Methods in android?

Android provides many options for storage of persistent data. It provides the solution according to your need. The storages which have been provided in Android are as follows:-

Shared Preferences: Store private primitive data in key-value pairs

Internal Storage: Store private data on the device memory.

External Storage: Store public data on the shared external storage.

SQLite Databases: Store structured data in a private database.

Network Connection: Store data on the web with your own network server.

What is localization and how to achieve?

Localization is a way of representing the products in different languages. Android is an operating system which runs in many regions, so to reach different users localization is a must. Localization in Android can be achieved by incorporating different languages in the application which you are using. To do this knowledge of Java, XML elements, Activity lifecycle and general principles of internationalization and localization are required.
Rohit Sharma 12-11-2011
Android interview questions and answers.
Describe Briefly the Android Application Architecture.

Android application architecture allows the simplification and reuse of any application. It provides a better way to publish the capabilities of the application so that any other application can make good use of those capabilities. This architecture includes the following components:

Intent: perform some operation on some activity and service

Resource Externalization - such as strings and graphics

Notification signaling users - light, sound, icon etc.

Content Providers – sharing of data between various applications

What dialog boxes are supported in android?

There are 4 dialog boxes which have been supported by Android. These are as follows:
AlertDialog: it supports 0 to 3 buttons with a list of selectable elements that includes check boxes and radio buttons.

-ProgressDialog: it displays the progress of any dialog or application. It is an extension of AlertDialog and supports adding buttons.
-DatePickerDialog: it is used to give provision to the user to select the date
- TimePickerDialog: it is used to give provision to the user to select the time
Rohit Sharma 12-11-2011
Android interview questions and answers.
What is APK format in Android? How to make an APK file?

APK termed as Application package file is a format that is used to distribute and install the application software for android, and middleware on the android operating system. To make an APK file, first android is compiled and then all of its parts are grouped in one file termed as package. The package consists of the entire program’s code (.dex files), resources, manifest file etc. The file is saved with .apk extension.

What is a Sticky Intent?

Intent is basically an abstract description of an operation that has to be performed for communication. Sticky Intent is also a type of intent which allows the communication between a function and a service. For example: sendStickyBroadcast() performs send Broadcast(Intent) which stays even after the broadcast is complete. It helps in retrieving the data quickly. The message ACTION_BATTERY_CHANGED of an operating system is an example of it.

How to Translate in Android?

Android uses Google translator to translate data from one language into another language using XAMPP. XAMPP is used to transmit the data. The steps which have to be followed are: Type the message in your language, go to the language setting, a list will be displayed there, select the language from the list to convert your text.
Rohit Sharma 12-11-2011