Android3 Intent和IntentFilter

Intent意思为意图,就是下一步要做的事情。

包括

1

ComponentName:对象用于表示唯一的长须应用组件,指明了期望的intent组件,即下一步要执行的组件。是activity转换的一种方法。

2

Action:实际上是intent所触发动作名称的字符串。

3

Data:主要是对intent消息中的数据惊醒封装,病描述intent的Action所操作数据的url(资源定位符)以及类型(根据格式区分类型),这样就能通过相对应的程序打开这个data

4

Category:对目标组件类信息的描述(比如对activity属性的描述)

5

Extra:中封装了一些附加的i型你先,这些信息已键值对的形式存在,intent可以通过putExtras()和Gerextras()来储存和获取信息。

一下为相应用法。

 

package com.example.inte;

import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button)findViewById(R.id.button1);
Button button2 = (Button)findViewById(R.id.button2);
Button button3 = (Button)findViewById(R.id.button3);
Button button4 = (Button)findViewById(R.id.button4);
button1.setOnClickListener(new OnClickListener(){
public void onClick(View V){

Intent intent=new Intent();
ComponentName cName=new ComponentName("com.example.inte",
"com.example.inte.OneActivity"
);
intent.setComponent(cName);
startActivity(intent);
}
});
button2.setOnClickListener(new OnClickListener(){
public void onClick(View V){

Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri=Uri.parse("http://www.baidu.com/");
intent.setData(uri);
startActivity(intent);
}
});
button3.setOnClickListener(new OnClickListener(){
public void onClick(View V){

Intent intent=new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
});
button4.setOnClickListener(new OnClickListener(){
public void onClick(View V){

String recevier = "1065194059@qq.com";
String ccStrings = "113654201@163.com";
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_EMAIL, recevier);
intent.putExtra(Intent.EXTRA_CC, ccStrings);
intent.putExtra(Intent.EXTRA_SUBJECT, "Theme");
intent.putExtra(Intent.EXTRA_TEXT, "This is a test email");
intent.setType("text/plain");
startActivity(intent);
}
});
}
}

 

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="79dp"
android:layout_toRightOf="@+id/textView1"
android:text="Button" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="32dp"
android:text="Button2" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:text="Button3" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button3"
android:layout_below="@+id/button3"
android:text="Button4" />

</RelativeLayout>

posted @ 2015-05-13 21:28  hitz&x  阅读(241)  评论(0编辑  收藏  举报