Android学习笔记之Intent

Intent是Activity之间的管道

可以用来做Acitivity的跳转或传递数据

protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		System.out.println("onCreate");
		TextView tv = null;
		btnStarAty1= (Button)findViewById(R.id.btnStartAty1);
		btnStarAty1.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View v){
				//从主界面跳转到Aty1
				Intent i = new Intent(MainActivity.this,Aty1.class);
                  
                   //传值 i.putExtra("txt","Hello aty1"); startActivity(i); } }); }

  Aty1接收值

@Override
    protected void onCreate(Bundle e){
        super.onCreate(e);
        setContentView(R.layout.aty1);
        btnClose = (Button)findViewById(R.id.btnClose);
        btnClose.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                finish();
            }
        });
        tvOut = (TextView)findViewById(R.id.tvOut);
        //找到Intent这个管道
        tvOut.setText(getIntent().getStringExtra("txt"));
    }

 

posted @ 2016-02-18 21:52  喜爱糖葫芦  阅读(170)  评论(0编辑  收藏  举报