AndrodApplicationEng 07march2012
AndrodApplicationEng 07march2012
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.
45
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
50
51
52
53
54
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
56
<?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
public class JenSecondActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); }
58
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
click
60
};
61
62
63
Exercise - implicit p
64