Intent - go from one activity to other and many more..

An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and Context.startService(Intent) or Context.bindService(Intent, ServiceConnection, int) to communicate with a background Service.  Its most significant use is in the launching of activities, where it can be thought of as the glue between activities.

There are two types of intents you will use.


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.

following code is found in manifest file. in which class name specified is nothing but a activity created by us.the intent-filter set activity as launcher activity. it means which activity has intent-filter shown first to android user on start.

<activity android:label="@string/title_notes_list" class=".NotesList">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN"/>
                   <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
</activity>


To launch activity when event occurs 

First we need to create object of that class and specify class of activity which we want to start.For instance,if we have button on click the method onBclick() is called and we want to launch second activity(SecondActivity).To do this we just need to add following code to the method,

public void onBclick(View view){
    Intent intent=new Intent(this,SecondActivity.class)
    startActivity(in);
}
 

Comments

Popular posts from this blog

Android virtual Device(AVD)-build and run program using Emulator

introduction to android

Simple Hello World Program