Android跳轉intent簡單教程

來源:互聯網
上載者:User

標籤:intent android

跳轉的方法:

1)簡單跳轉,沒有帶參的:

private void onClickLisener() {

// TODO Auto-generated method stub

btn_login_register.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

                                //意圖、意向,參數1:表示當前在哪裡,參數二:跳轉到哪裡

Intent intent=new Intent(MainActivity.this,Register.class);

                                //啟動意圖

MainActivity.this.startActivity(intent);

                                //關閉當前activity

                                MainActivity.this.finish();

}

});


1)  帶參數跳



btn_register_reg.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Intent intent=new Intent(Register.this,MainActivity.class);

String username=et_register_username.getText().toString();

String password=et_register_password.getText().toString();

int a=username.trim().length();

int b=password.trim().length();

if(a>0 && b>0){

intent.putExtra("username", username);

intent.putExtra("password", password);

startActivity(intent);

Register.this.finish();

}else{

//Toast.makeText(Register.this,"請輸入用戶名和大於8小於16位的密碼;", 2000);

                                        System.out.println("錯誤!");

}

}

});



//接收參數:

private void intent() {

// TODO Auto-generated method stub

Intent intent=getIntent();

String username=intent.getStringExtra("username");

String password=intent.getStringExtra("password");

et_login_user.setText(username);

et_login_password.setText(password);

System.out.println(username);

System.out.println(password);

}





本文出自 “9151568” 部落格,請務必保留此出處http://9161568.blog.51cto.com/9151568/1673553

Android跳轉intent簡單教程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.