Practical 4
Practical 4
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;
TextView txtStudentinfo;
txtStudentinfo = findViewById(R.id.txtusername);
txtStudentinfo.setText("RollNO: "+rollNo+",Name: "+name);
getSupportActionBar().setTitle(title);
Thank You