Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

INTENT IN ANDROID

ZAHID JAVED
INTENT
• Android uses Intent for communicating between the components of an
Application and also from one application to another application.

• 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.
MOVE ONE ACTIVITY TO ANOTHER
ACTIVITY
ACTIVITY
FIRST ACTIVITY
WHAT IS INTENT IN ANDROID?
➢Intent is a simple message object that is used to communicate
between android components such as activities, content
providers, broadcast receivers and services. Intents are also
used to transfer data between activities.

➢Intents are used generally for starting a new activity using


startActivity().
MAIN COMPONENTS

These four components to transfer data and communication with


each another than we use Intent.
INTENT WORKING
MAIN COMPONENTS
MAIN COMPONENTS
MAIN COMPONENTS
MAIN COMPONENTS
MAIN COMPONENTS
MAIN COMPONENTS
MAIN COMPONENTS
TYPES OF INTENTS:
Intent are of two types: Explicit Intent and Implicit Intent
TYPES OF INTENTS:
Intent are of two types: Explicit Intent and Implicit Intent
EXPLICIT INTENT:
• Explicit Intents are used to connect the application internally.
• In Explicit we use the name of component which will be affected by
Intent. For Example: If we know class name then we can navigate
the app from One Activity to another activity using Intent. In the
similar way we can start a service to download a file in background
process.
• Explicit Intent work internally within an application to perform
navigation and data transfer.
EXPLICIT INTENT:
SEND DATA USING INTENT IN VARIABLE
First Activity to send data
String FatherName="My Father Name is ShahDin";
Intent i=new Intent(this,MyNewActivity.class);
i.putExtra("UserName","My name Zahid Javed");
i.putExtra("MyFatherName",FatherName);
startActivity(i);
SECOND ACTIVITY
Receiving Side
TextView tvusername,tvfathername;

tvusername=findViewById(R.id.tvusername);
tvfathername=findViewById(R.id.tvfathername);

Intent myIntent=getIntent();
String Uname=myIntent.getStringExtra("UserName");
String Fname=myIntent.getStringExtra("MyFatherName");

tvusername.setText(Uname);
tvfathername.setText(Fname);
INTENT WORKFLOW
INTENT WORKFLOW
1. in content_one, user set name and email, and click button “Page
Two”
2. onclick listener will process value name and email, inside process
listener will create new intent object then add extra that will fill with
value name and email, after that startActivity for run the object intent.
3. get intent that was sent from one_activity, from object intent get value
name and email then set to textview object.
4. after process intent in two_activity, the content_two will show from
value of name and email that was set from intent.
ONEACTIVITY.JAVA
Button page_two_obj = findViewById(R.id.btn_page_two);
EditText name_obj = findViewById(R.id.txt_name);
EditText email_obj = findViewById(R.id.txt_email);

page_two_obj.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent_obj = new Intent(this, TwoActivity.class);
intent_obj.putExtra(“name”, name_obj.getText().toString());
intent_obj.putExtra(“email”, email_obj.getText().toString());
startActivity(intent_obj);
} });
ONEACTIVITY.JAVA
• Description :
• - Intent, is class that use for create object of intent
• - this, is context or current class
• - TwoActivity.class, is class target for intent redirect
• - putExtra, is method for add value to object intent
• - startActivity, is method for run intent
SECOND ACTIVITY.JAVA
TextView name_obj = (TextView)findViewById(R.id.tv_name_val);

TextView email_obj = (TextView)findViewById(R.id.tv_email_val);

Intent intent_obj = getIntent();

name_obj.setText(“Name : “ + intent_obj.getStringExtra(“name”));

email_obj.setText(“Email : “ + intent_obj.getStringExtra(“email”));
TWOACTIVITY.JAVA
Description :
- getIntent, is method for revive the object intent that was sent from activity one
- setText, is method for set value to object TextView
- getStringExtra, is method for get value from extra with return type string
IMPLICIT ACTIVITY
IMPLICIT ACTIVITY
REFERENCE

• https://sites.google.com/site/iotmobilemodule/4-intent/4-1-intent-workflow

You might also like