程序文件
/Chapter06_Intent_Category/src/com/amaker/test/MainActivity.java


package com.amaker.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* 测试Intent 的 Category属性
*/
public class MainActivity extends Activity {
// 声明 Button
private Button b1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置当前布局
setContentView(R.layout.main);
// 实例化 Button
b1 = (Button)findViewById(R.id.Button01);
// 为Button 添加监听器
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 实例化Intent
Intent i = new Intent();
// 添加Action属性
i.setAction(Intent.ACTION_MAIN);
// 添加Category属性
i.addCategory(Intent.CATEGORY_HOME);
// 启动Activity
startActivity(i);
}
});
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* 测试Intent 的 Category属性
*/
public class MainActivity extends Activity {
// 声明 Button
private Button b1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置当前布局
setContentView(R.layout.main);
// 实例化 Button
b1 = (Button)findViewById(R.id.Button01);
// 为Button 添加监听器
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 实例化Intent
Intent i = new Intent();
// 添加Action属性
i.setAction(Intent.ACTION_MAIN);
// 添加Category属性
i.addCategory(Intent.CATEGORY_HOME);
// 启动Activity
startActivity(i);
}
});
}
}
布局文件
/Chapter06_Intent_Category/res/layout/main.xml


<?
xml version="1.0" encoding="utf-8"
?>
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:orientation ="vertical" android:layout_width ="fill_parent"
android:layout_height ="fill_parent" >
< TextView
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:text ="Intent Category 测试" />
< Button
android:id ="@+id/Button01"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:text ="回到Home" ></ Button >
</ LinearLayout >
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:orientation ="vertical" android:layout_width ="fill_parent"
android:layout_height ="fill_parent" >
< TextView
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:text ="Intent Category 测试" />
< Button
android:id ="@+id/Button01"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:text ="回到Home" ></ Button >
</ LinearLayout >