0% found this document useful (0 votes)
12 views7 pages

Practical 4

The document discusses the concepts of Intent and Bundle Passing in Android application development. Intents facilitate navigation between applications and activities, while Bundles allow for efficient data transfer using key-value pairs. Code examples illustrate how to implement these concepts in a practical scenario.

Uploaded by

Naeem Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Practical 4

The document discusses the concepts of Intent and Bundle Passing in Android application development. Intents facilitate navigation between applications and activities, while Bundles allow for efficient data transfer using key-value pairs. Code examples illustrate how to implement these concepts in a practical scenario.

Uploaded by

Naeem Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

WELCOME

Mobile And Application


Development
Intent And Bundle Passing
Mobile And Application Development
Practical# 5

INSTRUCTOR: MUHAMMAD
NAEEM KHAN
What is Intent?
In Android, it is quite usual for users to witness a jump from one application to another as a part of the
whole process, for example, searching for a location on the browser and witnessing a direct jump into
Google Maps or receiving payment links in Messages Application (SMS) and on clicking jumping to
PayPal or GPay (Google Pay). This process of taking users from one application to another is achieved
by passing the Intent to the system. Intents , in general, are used for navigating among various
activities within the same application, but note, is not limited to one single application, i.e., they can be
utilized from moving from one application to another as well.
Intents could be Implicit, for instance, calling intended actions, and explicit as well, such as opening
another activity after some operations like on Click or anything else.
Below are some applications of Intents:
1. Sending the User to Another App
2. Getting a Result from an Activity
3. Allowing Other Apps to Start Your Activity
What is bundle passing in android?
It is known that Intents are used in Android to pass to the data from one activity to another. But there is
one another way, that can be used to pass the data from one activity to another in a better way and less
code space by using Bundles in Android. Android Bundles are generally used for passing data from one
activity to another. Basically here concept of key-value pair is used where the data that one wants to
pass is the value of the map, which can be later retrieved by using the key. Bundles are used with intent
and values are sent and retrieved in the same fashion, as it is done in the case of Intent. It depends on
the user what type of values the user wants to pass, but bundles can hold all types of values (int, String,
boolean, char) and pass them to the new activity.
The following are the major types that are passed/retrieved to/from a Bundle:
1. putInt(String key, int value), getInt(String key, int value)
2. putString(String key, String value), getString(String key, String value)
3. putStringArray(String key, String[] value), getStringArray(String key, String[] value)
4. putChar(String key, char value), getChar(String key, char value)
5. putBoolean(String key, boolean value), getBoolean(String key, boolean value)
Code
Mainactivity.java Mainactivity.java
Button btnNext; Button btnNext;

btnNext = findViewById(R.id.btnlogin); btnNext = findViewById(R.id.btnlogin);


Intent iNext;
Intent iNext;
iNext = new
iNext = new
Intent(MainActivity.this,activity2.class);
Intent(MainActivity.this,activity2.class);
btnNext.setOnClickListener(newView.On iNext.putExtra("title","Home");
ClickListener() { iNext.putExtra("StudentName","Ali");
@Override iNext.putExtra("RollNo","10");

public void onClick(View view) {


startActivity(iNext); btnNext.setOnClickListener(newView.OnClickListe
ner() {
@Override
public void onClick(View view) {
Code
Mainactivity2.java
Intent fromAct = getIntent();
String title = fromAct.getStringExtra("title");
String name = fromAct.getStringExtra("name");
int rollNo = fromAct.getIntExtra("RollNo",0);

TextView txtStudentinfo;
txtStudentinfo = findViewById(R.id.txtusername);
txtStudentinfo.setText("RollNO: "+rollNo+",Name: "+name);
getSupportActionBar().setTitle(title);
Thank You

You might also like