Professional Documents
Culture Documents
Lecture # 8
•The Intent describes the activity to start and carries any necessary data.
•If you want to receive a result from the activity when it finishes, call
startActivityForResult().
•You can start a service to perform a one-time operation (such as download a file)
by passing an Intent to startService().
•The Intent describes the service to start and carries any necessary data
To deliver a broadcast
•A broadcast is a message that any app can receive.
•The system delivers various broadcasts for system events, such as when the
system boots up or the device starts charging.
Action
Data
Category
Extras
Flags
Intent Types
•There are two types of intents:
•Implicit intents do not name a specific component, but instead declare a general
action to perform, which allows a component from another app to handle it. For
example, if you want to show the user a location on a map, you can use an
implicit intent to request that another capable app show a specified location on a
map.
Explicit intents
Intent CodeLearnFirstIntent = new Intent (getApplicationContext(), SecondActivity.class);
Implicit intents
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
Pass and Retrieving Data
Intent openNewActivity = new Intent(getApplicationContext(), Activity2.class);
startActivity(openNewActivity);
Pass data:
openNewActivity.putExtra("UserName", "Pranay");
openNewActivity.putExtra("isRegistered", true);
Retrieving data:
Intent intentObject = getIntent();
String userName = intentObject.getStringExtra("UserName");
boolean isRegistered = intentObject.getBooleanExtra("isRegistered", true);
Intent Filters
You have seen how an Intent has been used to call an another activity.
Android OS uses filters to pinpoint the set of Activities, Services, and Broadcast receivers
that can handle the Intent with help of specified set of action, categories, data scheme
associated with an Intent.
You will use <intent-filter> element in the manifest file to list down actions, categories
and data types associated with any activity, service, or broadcast receiver.
• http://www.tutorialspoint.com/android/android_intents_filters.htm