5 返回桌面 Intent的action 和 category 属性

来源:互联网 发布:软件开发精品课程 编辑:程序博客网 时间:2024/05/16 09:32

------------------------------------------main.java--------------------------------


package com.example.mk;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;


public class MainActivity extends ActionBarActivity {


//要加final,因为下面的 switch语句的case只能是常量,而不能是变量
private final int PICK_CONTACT = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


public void getOnClick(View view) {
//创建intent
Intent intent = new Intent();
//设置Intent的Action属性
intent.setAction(Intent.ACTION_MAIN);
//设置Intent的Category属性
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}


}


。。。。。。。。。。。。。。。。。。。。。。。main.xml。。。。。。。。。。。。。。。


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


<Button 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="返回桌面"
   android:onClick="getOnClick"
   />
</LinearLayout>

0 0
原创粉丝点击