Monday 24 November 2014

What is an Intent in Android ?

Intent is an intention to perform an operation.

It is used for-

1- To Start Component:

i)- Activity -> StartActivity and StartActivityforResult.

ii)- Service -> bindService / StartService

iii)- BroadCastReciever -> context.sendBroadcast

2- To Transfer data from one component to another ( Custom objects can be transfered by implementing parcelable or searilizable interfaces ).

3- Types of Intents:-

 i) Explicit Intent->

It is an Intent which contains explicit info. about component which will be started using the intent.

For Example:-

a)- Intent intent = new Intent( this , TestActivity.class );

b)- Intent intent = new Intent();
intent.setClassName( "packagename", fully qualified class name );

ii) Implicit Intent->

It is an Intent which doesn't specify component info. explicitly,but "Action" is used to find the component.

For Example:-

a)- Intent intent =  new Intent("Action");

b)- Intent intent = new Intent();
intent.setAction("action"); 


No comments:

Post a Comment