1.跳轉,代碼如下
- Button button=(Button)this.findViewById(R.id.button);
- button.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- // TODO Auto-generated method stub
- Intent intent=new Intent(FirstActivity.this,OtherUi.class);
- MulActivity.this.startActivity(intent);
- }
- });
2.用intent傳值
3.當前activity傳值到新activity的時候用
Intent intent=new Inten(FirstActivity.this,OtherUi.class);
intent.putExtra()然後新activity用this.getintent()
int型的就是 int **=intent.getIntExtra();
其他類型類推
4.新activity返回傳值用requestCode(要求碼)和resultCode(結果碼)
Intent intent=new Intent(); //數據是用Intent返回
intent.putExtra("result","My name is Jave!");//把返回數據存在intent中
OtherUi.this.setResult(RESULT_OK,intent);//設置返回數據OtherUi.this.finish();
而傳去的那個activity就:
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- // TODO Auto-generated method stub
- Log.i(TAG,"request code is"+requestCode+",resultCode is"+resultCode);//這是打印出信息
- if(resultCode==RESULT_OK)//結果碼
- {
- Log.i(TAG,"result="+data.getStringExtra("result"));
- }
- super.onActivityResult(requestCode,resultCode, data);
- }