安卓 利用Intent返回手机主界面

来源:互联网 发布:sql insert into 条件 编辑:程序博客网 时间:2024/04/28 18:29

1、布局:一个Button按钮即可


2、代码:

public class BackToHomeActivity extends Activity {private Button btn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.backtohome);btn = (Button) findViewById(R.id.btn_backtohome);btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent i = new Intent();i.setAction(Intent.ACTION_MAIN);i.addCategory(Intent.CATEGORY_HOME);startActivity(i);}});}}


0 0
原创粉丝点击