How to transfer and fetch data using intent.

Android application components can connect to other Android applications. This connection is based on a task description represented by an Intent object.

Intent are the objects which is used in android for passing the information among Activities in an Application and from one app to another also. Intent are used for communicating between the Application components and it also provides the connectivity between two apps.

For example: Intent facilitate you to redirect your activity to another activity on occurrence of any event. By calling, startActivity() you can perform this task.

In the above example, foreground activity is getting redirected to another activity i.e. MainActivity2.java. getApplicationContext() returns the context for your foreground activity.

Step 1: Create a new project in Android Studio and name it IntentDemo.

Step 2: Now go to res -> layout -> xml (or) activity_main.xml and add following code. Here we are designing in Linear Layout .

Activity_Main.Xml

Step 3: Now Create a new Activity. Go to res-> right click on layout-> new -> Activity -> Blank Activity and create activity_main2.xml activity. Here add following code.

Activity_Main2.Xml

Step 3: Now go to app -> AndroidManifest.xml and add following code. Here we are add Second Activity code

AndroidManifest.Xml

Step 4: Now open app -> java -> package, click on MainActivity.java and add the below code.

MainActivity.Java

Step 5: Now Create a new Activity. Go to java-> right click on new -> Activity -> Blank Activity and create Main2Activity activity.

Main2Activity.Java

Output :-

 

          

 

Leave a Reply

Your email address will not be published. Required fields are marked *