Thursday, 28 March 2013

Android Important interview questions and answer and some other important concepts


Android
Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers.
Android is open source and Google releases the code under the Apache License.
Android, Inc. was founded in Palo Alto, California in October 2003 by Andy Rubin, Rich Miner, Nick Sears and Chris White.
The first android phone was HTC G1.
Android Versions

1.0 – Android beta.
 1.5 – Android Cupcake.
  • Â 1.6 – Android Donut.
  • 2.0/2.1 – Eclair.
  • 2.2.x – Froyo.
  • 2.3.x – Gingerbread.
  • 3.x – Honeycomb (used mainly for tablets.)
  • 4.0.x – Ice Cream Sandwich (both for phones and tablets.)
4.1/4.2 – Jelly Bean (both for phones and tablets.)


Android Features

Handset layouts
The platform is adaptable to larger, VGA, 2D graphics library, 3D graphics library based onOpenGL ES 2.0 specifications, and traditional smartphone layouts.

Storage
SQLite, a lightweight relational database, is used for data storage purposes.

Connectivity
Android supports connectivity technologies including GSM/EDGE, IDEN, CDMA, EV-DO,UMTS,Bluetooth, Wi-Fi, LTE, NFC and WiMAX.

Messaging
SMS and MMS are available forms of messaging, including threaded text messaging and Android Cloud To Device Messaging (C2DM) and now enhanced version of C2DM, Android Google Cloud Messaging (GCM) is also a part of Android Push Messaging service.

Multiple language support
Android supports multiple languages.[4]

Web browser
The web browser available in Android is based on the open-source WebKit layout engine, coupled with Chrome's V8 JavaScript engine. The browser scores 100/100 on the Acid3 test on Android 4.0.

Java support
While most Android applications are written in Java, there is no Java Virtual Machine in the platform and Java byte code is not executed. Java classes are compiled into Dalvik executables and run on Dalvik, a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU. J2ME support can be provided via third-party applications.

Media support
Android supports the following audio/video/still media formats: WebM, H.263, H.264, AAC, HE-AAC (in 3GP or MP4 container),MPEG-4 SP, AMR, AMR-WB (in 3GP container), MP3, MIDI, Ogg Vorbis, FLAC, WAV, JPEG, PNG, GIF, BMP, WebP.[3]

Streaming media support
RTP/RTSP streaming (3GPP PSS, ISMA), HTML progressive download (HTML5 <video> tag). Adobe Flash Streaming (RTMP) and HTTP Dynamic Streaming are supported by the Flash plugin.[5] Apple HTTP Live Streaming is supported by RealPlayer for Android,[6] and by the operating
system in Android 3.0 (Honeycomb).[7]

Additional hardware support
Android can use video/still cameras, touchscreens, GPS, accelerometers, gyroscopes, barometers, magnetometers, dedicated gaming controls, proximity and pressure sensors, thermometers, accelerated 2D bit blits (with hardware orientation, scaling, pixel format conversion) and accelerated 3D graphics.

Multi-touch
Android has native support for multi-touch which was initially made available in handsets such as the HTC Hero. The feature was originally disabled at the kernel level (possibly to avoid infringing Apple's patents on touch-screen technology at the time).[8] Google has since released an update for the Nexus One and the Motorola Droid which enables multi-touch natively.[9]

Bluetooth
Supports A2DP, AVRCP, sending files (OPP), accessing the phone book (PBAP), voice dialing and sending contacts between phones. Keyboard, mouse and joystick (HID) support is available in Android 3.1+, and in earlier versions through manufacturer customizations and third-party applications.[10]

Video calling
Android does not support native video calling, but some handsets have a customized version of the operating system that supports it, either via the UMTS network (like the Samsung Galaxy S) or over IP. Video calling through Google Talk is available in Android 2.3.4 and later. Gingerbread allows Nexus S to place Internet calls with a SIP account. This allows for enhanced VoIP dialing to other SIP accounts and even phone numbers. Skype 2.1 offers video calling in Android 2.3, including front

camera support. Users with the Google+ android app can video chat with other google+ users through hangouts.

Multitasking
Multitasking of applications, with unique handling of memory allocation, is available.[11]

Accessibility
Built in text to speech is provided by Talk back for people with low or no vision. Enhancements for
people with hearing disabilities is available as is other aids.

Voice based features
Google search through voice has been available since initial release.[12] Voice actions for calling, texting, navigation, etc. are supported on Android 2.2 onwards.[13] As of Android 4.1, Google has expanded Voice Actions with the ability to talk back and read answers from Google's Knowledge Graph when queried with specific commands.[14] The ability to control hardware has not yet been implemented.

Tethering
Android supports tethering, which allows a phone to be used as a wireless/wired Wi-Fi hotspot. Before Android 2.2 this was supported by third-party applications or manufacturer customizations.[15]

Screen capture
Android supports capturing a screenshot by pressing the power and volume-down buttons at the same time.[16] Prior to Android 4.0, the only methods of capturing a screenshot were through manufacturer and third-party customizations or otherwise by using a PC connection (DDMS developer's tool). These alternative methods are still available with the latest Android.

External storage
Most Android devices include microSD slot and can read microSD cards formatted with FAT32, Ext3 or Ext4 file system. To allow use of high-capacity storage media such as USB flash drives and USB HDDs, many Android tablets also include USB 'A' receptacle. Storage formatted with FAT32 is handled by Linux Kernel VFAT driver, while 3rd party solutions are required to handle other popular file systems such as NTFS, HFS Plus and exFAT.


Features of Android OS

Linux Architecture
Opensource
Mobile OS
High Security
Multi-language Support
Choice of Hardware Support
No Syncronisation Required as compared to IPHONE
Sqlite Support
DVM Support
Application Framework Supports

Android Features:
Android has many amazing and unique features that are of significance to developers and users alike, some of which are:
  • Application Framework that enables reuse and replacement of components
  • Optimized Graphics that is powered by customized 2D graphics library and 3D graphics based on the OpenGL ES 1.0 specification
  • Media Support for common video, audio, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
  • Provision of Bluetooth, EDGE, 3G and Wi-Fi
  • SQLite for structured data storage
  • Open source WebKit engine based integrated web browser
  • Camera, GPS, Compass, and Accelerometer (dependent on hardware support)
  • GSM Telephony
  • Dalvik virtual machine optimised for mobile devices
  • Rich Development environment that includes a device emulator, debugging tools, performance and memory profiling and a Eclipse IDE plugin.



*******************************************************************






Thursday, 21 March 2013

what is broadcast receiver and broadcast receiver simple example


What is BroadCast Receiver in android ?
    Ans- Only an Intent (for which it is registered) can bring it into action. The Broadcast Receiver’s job is to pass a notification to the user, in case a specific event occurs.
    Using a Broadcast Receiver, applications can register for a particular event. Once the event occurs, the system will notify all the registered applications.

There are Two Way to Register BroadCast Receiver --
  1. Static : Use <receiver> tag and register in menifest file
  2. Dynamic : Context.registerReceiver() to add dynamically .

There are two main Classes Of BroadCast --
  1. Normal BroadCast- the registered receivers often run all at the same time. This is very efficient, but the Receivers are unable to utilize the results.
  2. Ordered BroadCast - These broadcasts are synchronous, and therefore follow a specific order. The order is defined using android: priority attribute.

Difference between Activity Intent and Broadcast Intent --
The intent used to start an Activity makes changes to an operation the user is interacting with, so the user is aware of the process. However, in case of broadcasting intent, the operation runs completely in the background, and is therefore invisible to the user.

Create A BroadCast Recevier with following steps--

  1. Creating Sub Class of BroadCast Recevier
  2. Overriding onReceiver() method of BraodCast Receiver class with following arguments-
  • Context (Indicate reference to your application)
  • Intent

Sercurity in BroadCast Receiver

As the broadcast receivers have a global work-space, security is very important concern here. If you do not define the limitations and filters for the registered receivers, other applications can abuse them.
Here are a few limitations that might help:
  • Whenever you publish a receiver in your application’s manifest, make it unavailable to external applications by using android: exported=”false”. You might think that specifying Intent filters.
  • Similarly, when you register your receiver using registerReceiver, any application may send it broadcasts. This can be prevented using permissions as well.
  • When you send a broadcast, it is possible for the external applications too to receive them. This can be prevented by specifying a few limitations.

Example of BroadCast Receiver in android

Receiving SMS using BroadCast Receiver with the following steps --

  1. Create a Sub Class of Braodcast Receiver with the follow code which will receiver the SMS


package com.example.sms_receiving;

import android.content.*;
import android.os.Bundle;
import android.telephony.*;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

Bundle bundle = intent.getExtras();

Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0;n< messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}

// show first message
Toast toast = Toast.makeText(context,
"Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
}

}
    2 - Now Register your Receiver in android menifest file as follows-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sms_receiving"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
/** This is the Receiver registration in android menifest **/
<receiver
android:name=".SMSReceiver">
</receiver>
/** ----------------------------------------------------------**/
</application>

</manifest>

Now when ever Receiver will receiver the message then it will Toast the message to the user screen .

Some Important Topic Of Android With There Practical Example


Tuesday, 12 February 2013

Acitivity Life Cycle Example


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
    String tag = "LifeCycleEvents";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       Log.d(tag, "In the onCreate() event");
    }
    public void onStart()
    {
       super.onStart();
       Log.d(tag, "In the onStart() event");
    }
    public void onRestart()
    {
       super.onRestart();
       Log.d(tag, "In the onRestart() event");
    }
    public void onResume()
    {
       super.onResume();
       Log.d(tag, "In the onResume() event");
    }
    public void onPause()
    {
       super.onPause();
       Log.d(tag, "In the onPause() event");
    }
    public void onStop()
    {
       super.onStop();
       Log.d(tag, "In the onStop() event");
    }
    public void onDestroy()
    {
       super.onDestroy();
       Log.d(tag, "In the onDestroy() event");
    }
}