import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText; /**
* activity之间传递数据&批量传递数据
* @author dr
*/
public class Demo1Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
} public void click(View view){
EditText et = (EditText) this.findViewById(R.id.et_activity01);
String content = et.getText().toString().trim(); Intent intent = new Intent(this,Demo2Activity.class);
// intent.putExtra("cn.itcast.passdata.name", content);
//基本数据类型 和基本数据类型的数组 我们都可以通过intent传递 // 批量传递数据
Bundle bundle = new Bundle();
bundle.putString("cn.itcast.passdata.name", content); intent.putExtras(bundle); startActivity(intent);
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView; public class Demo2Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2); //获取到激活他的意图
Intent intent = getIntent();
// String name = intent.getStringExtra("cn.itcast.passdata.name");
Bundle bundle = intent.getExtras();
String name = bundle.getString("cn.itcast.passdata.name"); TextView tv =(TextView) this.findViewById(R.id.tv_activity02);
tv.setText("你好 :"+name);
}
}