Professional Documents
Culture Documents
Intent in Android
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.
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);
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