Tuesday, March 29, 2011

Localization, Boot Process and Sensor

1) What is localization and how to achieve it ?
Answer :-
Android will run on many devices in many regions. To reach the most users, your application should handle text, audio files, numbers, currency, and graphics in ways appropriate to the locales where your application will be used. For more details you can refer : http://developer.android.com/resources/tutorials/localization/index.html


2) You have 4 activity in your application Activity1, Activity2, Activity3, Activity4 and i want to make one of them as the main activity so that when the user select the application in the launcher that particular activity is shown how you do this ?
Answer :- Suppose if i want to make Activity3 as the main activity then we have to make a changes in AndroidManifest.xml .
<activity class=".Activity3" android:label="@string/Activity_3">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
</activity>

3) What are the launch mode in android? What are the types of launch mode for an activity and which one is default ?
Answer :-
An instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) inIntent objects to determine what should happen when the activity is called upon to handle an intent. They are:
     "standard"
     "singleTop"
     "singleTask"
     "singleInstance"
The default mode is "standard".
<activity>
android:launchMode=["multiple" | "singleTop" | "singleTask" | "singleInstance"]
</activity>


4) Give a example of implicit intent and explicit intent ?
Answer :-

Implicit Intents - Opening an URL
          Intent implicitIntent = new Intent();
          Uri url=Uri.parse("http://www.ea.com");
          implicitIntent.setAction(Intent.ACTION_VIEW);
          implicitIntent.setData(url);
          context.startActivity(implicitIntent);
Explicit intents - Data transfer between activities
          Intent explicitIntent = new Intent( this, anotherActivity.class );
          explicitIntent.putExtra( "int", 5);
          explicitIntent.putExtra( "string", "hello" );
          startActivity(explicitIntenti);


5) What is the android boot process from power on ?
Answer :- I don't have too much experience in android to give the answer of this question, so please visit this url. This is helpfull to understand the boot process of android devices from power on.  http://www.androidenea.com/2009/06/android-boot-process-from-power-on.html

6) What is Sensor in Android ?
Answer :-
SensorManager lets you access the device's sensors. Get an instance of this class by calling Context.getSystemService() with the argumentSENSOR_SERVICE. Always make sure to disable sensors you don't need, especially when your activity is paused. Failing to do so can drain the battery in just a few hours. Note that the system will not disable sensors automatically when the screen turns off.
public class SensorActivity extends Activity, implements SensorEventListener {
     private final SensorManager mSensorManager;
     private final Sensor mAccelerometer;
     public SensorActivity() {
         mSensorManager = 
         (SensorManager)getSystemService(SENSOR_SERVICE);
         mAccelerometer = 
         mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
     }
     protected void onResume() {
         super.onResume();
         mSensorManager.registerListener(this, mAccelerometer,     
         SensorManager.SENSOR_DELAY_NORMAL);
     }
     protected void onPause() {
         super.onPause();
         mSensorManager.unregisterListener(this);
     }
     public void onAccuracyChanged(Sensor sensor, int accuracy) {
     }
     public void onSensorChanged(SensorEvent event) {
     }
}

7) What is data synchronization in android ?
Answer :-

8) Suppose i have one Activity in application 2 and i want to use that Activity in application 1. How we achieve this ?
Answer :- 

Thursday, March 24, 2011

Event, AIDL, Screen Resolution and Orientation

1) How many types of Events in Android ?
Answer :-

onKeyDown :-  onKeyDown Called when any device key is pressed; includes the D-pad, keyboard, hang-up, call, back, and camera buttons.
@Override
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
     // Return true if the event was handled.
     return true;
}
onKeyUp :- onKeyUp Called when a user releases a pressed key.
@Override
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
     // Return true if the event was handled.
     return true;
}
onTrackballEvent :- onTrackballEvent Called when the device’s trackball is moved
@Override
public boolean onTrackballEvent(MotionEvent event ) {
     // Get the type of action this event represents
     int actionPerformed = event.getAction();
     // Return true if the event was handled.
     return true;
}
onTouchEvent :- onTouchEvent Called when the touch screen is pressed or released, or it detects movement.
@Override
     public boolean onTouchEvent(MotionEvent event) {
     // Get the type of action this event represents
     int actionPerformed = event.getAction();
    // Return true if the event was handled.
    return true;
}

2) What is Sandboxing ?
Answer :-
 Each application in Android runs in its own process. An application cannot directly access another application's memory space. This is called application sandboxing.

3) What is AIDL in Android ? How we achieve Interprocess communication (IPC) protocol in Android ?
Answer :-
In order to allow cross-application communication, Android provides an implementation of Interprocess Communication (IPC) protocol. IPC protocols tend to get complicated because of all the marshaling/un marshaling of data that is necessary.
                        To help with this, Android provides Android Interface Definition Language, or AIDL. It is a lightweight implementation of IPC using a syntax that is very familiar to Java developers, and a tool that automates the stub creation.

4) How we handle multiple screen resolution in Android ?
Answer :-

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
...
</manifest>
The objective of supporting multiple screens is to create an application that can run properly on any display and function properly on any of the generalized screen configurations supported by the platform.
You can easily ensure that your application will display properly on different screens. Here is a quick checklist:
  • Use wrap_content, fill_parent, or the dp unit (instead of px), when specifying dimensions in an XML layout file 
  • Do not use AbsoluteLayout 
  • Do not use hard coded pixel values in your code 
  • Use density and/or resolution specific resources
5) How we manage Screen Orientation in Android ?
Answer :-

Changing the Screen Orientation Based on the Accelerometer :- If you want to change the screen orientation automatically based on the positioning of the device, you can use the android:screenOrientation attribute in the AndroidManifest.xml file:
<manifest> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
<activity android:name=".Orientation" 
             android:screenOrientation="sensor"               
             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 above specifies that the screen orientation for the Orientation activity is based on the sensor (accelerometer) of the device. If you hold the device upright, the screen will be displayed in portrait mode; if you hold it sideways, it will change to landscape mode.

Changing the Screen Orientation Programmatically :- There are times where you need to ensure that your application is displayed only in a certain orientation. For example, suppose you are writing a game that should only be viewed in landscape mode. In this case, you can programmatically force a change in orientation using the setRequestOrientation() method of the Activity class: 
import android.app.Activity; 
import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
public class Orientation extends Activity { 
  /** Called when the activity is first created. */ 
  @Override 
  public void onCreate(Bundle savedInstanceState) {     
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    //---change to landscape mode---   
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);   
  } 

To change to portrait mode, use the ActivityInfo.SCREEN_ORIENTATION_PORTRAIT constant:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

Besides using the setRequestOrientation() method, you can also use the android:screenOrientation attribute on the <activity> element in AndroidManifest.xml as follows to fix the activity to a certain orientation: 

<manifest> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
<activity android:name=".UIActivity" android:screenOrientation="landscape" 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 above example fixes the activity to a certain orientation (landscape in this case) and prevents the activity from being destroyed; that is, the activity will not be destroyed and the onCreate event will not be fired again when the orientation changes.


Monday, March 21, 2011

Sound, Vibrate and Data Storage etc.

1) How we play a sound in Android
Answer :- We use android.media.MediaPlayer.
Playing from a Raw Resource :- Perhaps the most common thing to want to do is play back media (notably sound) within your own applications. Doing this is easy:
Put the sound (or other media resource) file into the res/raw folder of your project, where the Eclipse plugin (or aapt) will find it and make it into a resource that can be referenced from your R class
Create an instance of MediaPlayer, referencing that resource using MediaPlayer.create, and then call start() on the instance:
         MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);
         mp.start();

To stop playback, call stop(). If you wish to later replay the media, then you must reset() and prepare() the MediaPlayer object before calling start() again. (create() calls prepare() the first time.). To pause playback, call pause(). Resume playback from where you paused with start().

Playing from a File or Stream :- You can play back media files from the filesystem or a web URL:
Create an instance of the MediaPlayer using new
Call setDataSource() with a String containing the path (local filesystem or URL) to the file you want to play
First prepare() then start() on the instance:
      MediaPlayer mp = new MediaPlayer();
      mp.setDataSource(PATH_TO_FILE);
      mp.prepare();
      mp.start();

2) What is difference between prepare() and prepareAsync() 
Answer :- There are two ways (synchronous vs. asynchronous) that the Prepared state can be reached: either a call to prepare() (synchronous) which transfers the object to the Prepared state once the method call returns, or a call to prepareAsync() (asynchronous) which first transfers the object to the Preparing state after the call returns (which occurs almost right way) while the internal player engine continues working on the rest of preparation work until the preparation work completes. When the preparation completes or when prepare() call returns, the internal player engine then calls a user supplied callback method, onPrepared() of the OnPreparedListener interface, if an OnPreparedListener is registered beforehand via setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener).
                                    The main difference is that when we use files then we call prepare() and when we use streams then we call prepareAsync().

3) How we play vibrate in Android 
Answer:-
android.os.Vibrator
public class VibrateGame
{
   Vibrator v;
   public VibrateGame(Context context)
  {
     v = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
  }
  public void vibrateGame(int ms)
  {
     v.vibrate(ms);
  }
}

4) What is SharedPreferences in Android and how we implement it ? 
Answer :- The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can useSharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
To get a SharedPreferences object for your application, use one of two methods:
getSharedPreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.
getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name.

To write values:
1. Call edit() to get a SharedPreferences.Editor.
2. Add values with methods such as putBoolean() and putString().
3. Commit the new values with commit()
To read values, use SharedPreferences methods such as getBoolean() and getString().

// Create Object
SharedPreferences setting = getSharedPreferences("SAVE_FILE", 0);
SharedPreferences.Editor editor = setting.edit();

// For Store The Value
editor.putInt("ypad", canvas.ypad);
editor.putBoolean("up", canvas.up);
editor.commit();

// For Retrieving The Value
canvas.ypad = setting.getInt("ypad", 0);
canvas.up=setting.getBoolean("up", false);

What do u meant 0 and false in above ?
0 and false - Value to return if this preference does not exist. Throws ClassCastException if there is a preference with this name that is not a long

What do u mean by 0 in SharedPreferences setting = getSharedPreferences("SAVE_FILE", 0);
public abstract SharedPreferences getSharedPreferences (String filename, int mode)

There are 3 types of File creation mode:
0 - MODE_PRIVATE - the default mode, where the created file can only be accessed by the calling application
1 - MODE_WORLD_READABLE - allow all other applications to have read access to the created file.
2 - MODE_WORLD_WRITEABLE - allow all other applications to have write access to the created file.

5) How we implement SQLite in Android ?
Answer :- Android provides full support for SQLite databases. Any databases you create will be accessible by name to any class in the application, but not outside the application. The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database. For example:

public class DictionaryOpenHelper extends SQLiteOpenHelper 
{
     private static final int DATABASE_VERSION = 2;
     private static final String DICTIONARY_TABLE_NAME = "dictionary";
     private static final String DICTIONARY_TABLE_CREATE =
     "CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +
     KEY_WORD + " TEXT, " +
     KEY_DEFINITION + " TEXT);";

    DictionaryOpenHelper(Context context) {
         super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
     
    @Override
     public void onCreate(SQLiteDatabase db) {
          db.execSQL(DICTIONARY_TABLE_CREATE);
     }
}
You can then get an instance of your SQLiteOpenHelper implementation using the constructor you've defined. To write to and read from the database, call getWritableDatabase() and getReadableDatabase(), respectively. These both return a SQLiteDatabase object that represents the database and provides methods for SQLite operations.
Android does not impose any limitations beyond the standard SQLite concepts. We do recommend including an autoincrement value key field that can be used as a unique ID to quickly find a record. This is not required for private data, but if you implement a content provider, you must include a unique ID using the BaseColumns._ID constant.
You can execute SQLite queries using the SQLiteDatabase query() methods, which accept various query parameters, such as the table to query, the projection, selection, columns, grouping, and others. For complex queries, such as those that require column aliases, you should use SQLiteQueryBuilder, which provides several convienent methods for building queries.
Every SQLite query will return a Cursor that points to all the rows found by the query. The Cursor is always the mechanism with which you can navigate results from a database query and read rows and columns.


View, Intent, IntentFilters, Layout and Adapter etc.

1) What is View
Answer :-
This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.).

2) What is Intent ? There are two types of Intent what are those and how they are different with each other ?
Answer:-
 An intent is an Intent object that holds the content of the message. The three components — activities, services, and broadcast receivers — are activated by asynchronous messages called intents. Intents can be divided into two groups: Explicit Intents and Implicit Intents.
  • Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application. 
  • Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent 
3) What are IntentFilters ?
Answer :- A component's intent filters inform Android of the kinds of intents the component is able to handle or we can say that to inform the system which implicit intents they can handle. 


3) What are the different UI Layout ?
Answer :-
The standard Layouts are:
  • LinearLayout :- A Layout that arranges its children in a single column or a single row. The direction of the row can be set by calling setOrientation(). 
  • RelativeLayout :- A Layout where the positions of the children can be described in relation to each other or to the parent. 
  • TableLayout :- A layout that arranges its children into rows and columns. The rows are defined in the layout XML, and the columns are determined automatically by Android. 
  • FrameLayout :- FrameLayout is designed to display a single item at a time. You can have multiple elements within a FrameLayout but each element will be positioned based on the top left of the screen. 
  • AbsoluteLayout :- A layout that lets you specify exact locations (x/y coordinates) of its children. 
4) What is LayoutInflater in Android ?
Answer :-
 This class is used to instantiate layout XML file into its corresponding View objects. It is never be used directly -- use getLayoutInflater() or getSystemService(String) to retrieve a standard LayoutInflater instance that is already hooked up to the current context and correctly configured for the device you are running on.

5) What is Adapter in Android ?
Answer :-
 An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

6) What is AdapterView ?
Answer :-
 An AdapterView is a view whose children are determined by an Adapter.

7) What is ContentValues and Cursor ?
Answer :-
ContentValues class is used to store a set of values that the ContentResolver can process.
             Cursor interface provides random read-write access to the result set returned by a database query

8) Content Provider is necessary for SQLite.
Answer :-
 No, Android provides a way for us to expose even our private data to other applications — with a content provider. A content provider is an optional component that exposes read/write access to your application data, subject to whatever restrictions you want to impose

9) How we draw a bitmap image ?
Bitmap imgBall=null;
BitmapDrawable b=(BitmapDrawable)getResources().getDrawable(R.drawable.ball);
imgBall=b.getBitmap();
canvas.drawBitmap(imgBall, xball, yball, paintObject); 
The Paint class holds the style and color information about how to draw geometries, text and bitmaps.

10)How we destroy/finish/kill/exit from application in Android ?
Answer :-
Call finish()

Saturday, March 19, 2011

Services, BroadCast Reciever and Content Provider

1) What is Services ?
Answer :- A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something.

2) What is Life Cycle of Services ?
Answer :- There are two ways to start a services.
Context.startService()   Context.bindService()


3) What is difference between Context.startService() and Context.bindService() ?
Answer :-
Context.startService() -> A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it.
Context.bindService() -> A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.



4) What is Bound Services ?
Answer :- A bound service is the server in a client-server interface. A bound service allows components (such as activities) to bind to the service, send requests, receive responses, and even perform interprocess communication (IPC). A bound service typically lives only while it serves another application component and does not run in the background indefinitely.


5) What is BroadCast Reciever ?
Answer :- A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in system code — for example, announcements that the timezone has changed, that the battery is low, that a picture has been taken, or that the user changed a language preference. All receivers extend the BroadcastReceiver base class. A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

6) What is Content Provider ?
Answer :- Content providers store and retrieve data and make it accessible to all applications. They're the only way to share data across applications. For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don't need to share data amongst multiple applications you can use a database directly via SQLiteDatabase.
Content Provider is achived by a ContentResolver interface. Requests to ContentResolver are automatically forwarded to the appropriate ContentProvider instance. The primary methods that need to be implemented are:

  • onCreate() which is called to initialize the provider
  • query(Uri, String[], String, String[], String) which returns data to the caller
  • insert(Uri, ContentValues) which inserts new data into the content provider
  • update(Uri, ContentValues, String, String[]) which updates existing data in the content provider
  • delete(Uri, String, String[]) which deletes data from the content provider
  • getType(Uri) which returns the MIME type of data in the content provider
Data access methods (such as insert(Uri, ContentValues) and update(Uri, ContentValues, String, String[])) may be called from many threads at once, and must be thread-safe. Other methods (such as onCreate()) are only called from the application main thread.

7) Give a small example of Content Provider ?
Answer :- 
In ContentUserDemo.java
package org.example.contprov;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ContentUserDemo extends Activity {
private static final String TAG = "ContentUserDemo";
private ArrayList<String> list;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Get content provider and cursor
ContentResolver r = getContentResolver();
Cursor cursor = r.query(People.CONTENT_URI, null, null, null, null);

// Let activity manage the cursor
startManagingCursor(cursor);
Log.d(TAG, "cursor.getCount()=" + cursor.getCount());

// Get value from content provider
int nameIndex = cursor.getColumnIndexOrThrow(People.NAME);
int numberIndex = cursor.getColumnIndexOrThrow(People.NUMBER);

cursor.moveToFirst();
list = new ArrayList<String>();
do {
String name = cursor.getString(nameIndex);
String number = cursor.getString(numberIndex);
list.add(name + ": " + number);
} while (cursor.moveToNext());

// Get the list view
ListView listView = (ListView) findViewById(R.id.listView);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
listView.setAdapter(aa);
}
}

In layout/main.xml :- This layout just dumps the data in a ListView. One interesting part is linking the ArrayAdapter to the ListView, in the previous file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/listView"></ListView>
</LinearLayout>

AndroidManifest.xml :- Don't forget to ask for permission to read the contacts from the system Content Provider.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.cp" android:versionCode="1" android:versionName="1.0.0">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ContentUserDemo" 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>

Results :- You should see the list of people from your Contacts printed in your own application.







Friday, March 18, 2011

Activity In Android

1) What are the 4 basic Component in Android ?

  • Activities 
  • Services 
  • Broadcast receivers 
  • Content providers 
2) What is an Activity ?
Answer :- An activity is the equivalent of a Frame/Window in GUI toolkits. It takes up the entire drawable area of the screen (minus the status and title bars on top). An activity is what gets bound to the AndroidManifest.xml as the main entry point into an application

3) What is the lifecycle of an Activity ?




4) If any Activity is running, in which state it goes when we press "Back" button and "Home" button ?
Answer :-

Back -> onPause -> onStop -> onDestroy . If again i start the Activity then onStart -> onResume -> Activity is visible.
Home -> onPause -> onStop -> If again i start the Activity then onRestart -> onStart -> onResume -> Activity is visible.

5) What are the 2 ways of starting Activity ?
Answer :-
Two ways to start Activity is
(i) public abstract void startActivity (Intent intent)
            Context.startActivity(intentObject);
(ii) public void startActivityForResult (Intent intent, int requestCode)

When we call the 2nd method ?
One activity often starts the next one. If it expects a result back from the activity it's starting, it calls startActivityForResult() instead of startActivity(). For example, if it starts an activity that lets the user pick a photo, it might expect to be returned the chosen photo. The result is returned in an Intent object that's passed to the calling activity's onActivityResult() method.

6) How you calculate the height and width of canvas in Activity class?
Answer :-
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height=display.getHeight();

7) How we pass information between one activity to another activity? How we pass object and ArrayList etc.
Answer :-
Let assume that there is a two Activity i.e A and B. we have to pass a data from Activity A to Activity B.

public class A extends Activity
{
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
         // CODE HERE
         Intent i = new Intent( this, B.class );
         i.putExtra( "int", 5);
         i.putExtra( "string", "hello" );
         public Intent putIntegerArrayListExtra (String name,
         ArrayList<Integer> value);
         public Intent putStringArrayListExtra (String name,
         ArrayList<String> value);
         public Intent putExtra (String name, Serializable value);
         public Intent putExtra (String name, Bundle value);
         startActivity( i );
   }
}
public class A extends Activity
{
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
         // CODE HERE
         Intent i = getIntent();
         int number = i.getIntExtra("int", -1);
         String str = i.getStringExtra("string");
         public ArrayList<Integer> getIntegerArrayListExtra (String name);
         public ArrayList<String> getStringArrayListExtra (String name);
         public Serializable getSerializableExtra (String name);
         public Bundle getBundleExtra (String name);
   }
}

8) How we can open a browser from a Activity/View ?
Answer :-
            Intent launchBrowser = new Intent();
            Uri url=Uri.parse("http://www.ea.com");
            launchBrowser.setAction(Intent.ACTION_VIEW);
            launchBrowser.setData(url);
            context.startActivity(launchBrowser);

9) When onSaveInstanceState() is call?

10) Suppose there is 2 Activity i.e Activity A and Activity B? A is in foreground and B in on background? What is the state of both activity?