0% found this document useful (0 votes)
61 views22 pages

AndrodApplicationEng 07march2012

- Activate three components of an application including an activity, activity service, and service broadcast receiver. - Intents contain information like the component name, action, data, category, extras, and flags. Common actions include VIEW, EDIT, and MAIN. - Explicit intents designate a specific target component class, while implicit intents do not specify the target and can activate components in other apps. - To add a new activity, create an activity class, layout XML file, and reference the activity in the manifest.

Uploaded by

Richard Abbott
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views22 pages

AndrodApplicationEng 07march2012

- Activate three components of an application including an activity, activity service, and service broadcast receiver. - Intents contain information like the component name, action, data, category, extras, and flags. Common actions include VIEW, EDIT, and MAIN. - Explicit intents designate a specific target component class, while implicit intents do not specify the target and can activate components in other apps. - To add a new activity, create an activity class, layout XML file, and reference the activity in the manifest.

Uploaded by

Richard Abbott
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Intent

Intent
Activate three components of an application.
activity, activity service, service broadcast receiver

Contains
Component
The name of the component

Action
A string naming of the action to be perform

Data
The URI of the data to be acted on The MIME type of that data

Category
A String containing additional information about the kind of component

Extras
Key-value pairs for additional information

Flags
Many instruct the Android system how to launch an activity
44

Intent
The primary pieces of information in an intent are:
action The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, AC TION_MAIN, etc. data d t The data to operate on, such as a person record in the contacts database, expre ssed as a Uri.

Some examples of action/data pairs are:


ACTION_VIEW content://contacts/people/1 ACTION DIAL content://contacts/people/1 ACTION_DIAL ACTION_DIAL tel:123 ACTION_EDIT content://contacts/people/1 ACTION_VIEW content://contacts/people/ ACTION_CALL tel:123

45

Explicit p intent & Implicit p intent


explicit intent
Explicit intents designate the target component by its name

implicit intent
Implicit intents do not name a target Implicit intents are often used to activate components in other applications pp

46

Explicit p intent

47

Implicit p intent
Intent intent = new Intent(); intent.setAction(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager. ( QUERY, "searchString"); " ") startActivity(intent);

Uri uri = Uri.parse( "tel:010512"); Intent intent = new Intent(Intent Intent(Intent.ACTION_DIAL, ACTION DIAL uri); startActivity(intent);

48

StartActivity y
example

49

How to add an Activity y

50

How to add an Activity y

51

How to add an Activity y

The name of a class to be added

52

How to add a layout y XML file

53

How to add a layout y XML file

54

How to add a layout y XML file

A full name of the xml file File-based resource names must contain only lowercase a-z, 0-9 or _

55

Exercise - explicit p

click

Main Activity

The second Activity

56

Exercise explicit p intent


A layout XML file of the second Activity

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout y _width="fill_p parent" android:layout_height="fill_parent" > <TextView android:text="This is the second activity of this application" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>

57

Exercise explicit p intent


onCreate() of the second Activity

public class JenSecondActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); }

58

Exercise explicit p intent


onClickListener of the main Activity

Button btn = (Button)findViewById(R.id.Button01); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(); i.setClass(JStartActivity.this, JenSecondActivity.class); startActivity(i); } });

59

Exercise implicit p intent

click

60

Exercise implicit p intent


OnClickListener mListener = new OnClickListener() { public void onClick(View v) { if(v.getId() == R.id.btn_snd) { Intent i = new Intent(); i.setClass(Jen_ActivityTestActivity.this, y y MySecondActivity.class); y y startActivity(i); } else if (v.getId()== R.id.btn_call) { Intent i = new Intent(); i.setAction(Intent.ACTION_CALL); i.setData(Uri.parse("tel:012345678")); startActivity(i); }

};

61

Exercise implicit p intent


Add a uses permission in the menifest file

62

Exercise implicit p intent


Add a uses permission in the menifest file

63

Exercise - implicit p

64

You might also like