Android中如何使用Intent打开新界面,并且进行传值

我需要在Mainactivity.java中打开ShowProdure.java,其中的一个传值为‘String=’,和坐标(0,0),谢谢

Intent Intent=new Intent(this,show.class);
Intent.putExtra传字符串
Intent.putInt传数值
startActivity(Intent);无返回值跳转
startActivityForResultExtraActivityForResult(Intent,0)处理返回值。

showActivity中取值
getIntent().getStringExtra取字符串
getIntent().getIntExtra取数值

谢谢,试过了,以上方法都可以使用传值,经过我的总结,有以下几种方法可以用来给Intent对象传值
//创建一个意图
Intent intent=new Intent(this,MainActivity2.class);
//第一种传值方式,创建一个Bundle对象
Bundle value=new Bundle();
value.putString("name","xingxing");
value.putInt("age", 20);
value.putLong("id",100);
intent.putExtra("person", value);
//第二种传值方式
intent.putExtra("name", "苏姑娘");

    //传递自定义数据
    Person_friend person_friend=new  Person_friend();
    person_friend.id=100;
    person_friend.name="苏姑娘";
    person_friend.color="Yellow";
    intent.putExtra("person_friend", person_friend);
    //启动另外一个Activity
    startActivity(intent);
    并且有相应的取值方式:
    //获取上一个Activity传来的值
    Intent intent=getIntent();
    Bundle bundle=intent.getBundleExtra("person");
    String name=bundle.getString("name");
    int age=bundle.getInt("age");
    long id=bundle.getLong("id");

    String name2=intent.getStringExtra("name");

    Person_friend person_friend=(Person_friend) intent.getSerializableExtra("person_friend");
    TextView tv=(TextView) findViewById(R.id.textView1);
    tv.setText("name="+name+"  age="+age+"    id="+id);
    tv.setText("name="+name2+"  age="+age+"    id="+id+"\n"+person_friend);

Intent intent = new Intent(Mainactivity.this, ShowProdure.class);

    // 给Intent携带数据
    intent.putExtra("name", name);
        intent.putExtra("name", name);
startActivity(intent);

打开新的界面分为两种,一种是显示的,一种是隐式的,
显式的:修改 主activity 中为按钮点击事件:重写onclick函数

 public void onClick(View v){
        Intent intent = new Intent(MainAcrtivity.this,SecondeActivity.class);
        startActivity(intent);

 }

至于隐式的Intent调用方法,建议查看《第一行代码》,我也才开始学习

传递数据好麻烦,你自己看看吧,我也不会。::>_<::

有问题一起交流 goorwl@163.com

觉得第一个“string=”没必要传

 Intent intent = new Intent(MainAcrtivity.this,SecondeActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("x", String.valueOf(0));
                    bundle.putString("y", String.valueOf(0));
                    intent.putExtras(bundle);
                    startActivity(intent);

当然你也可以把坐标写成一个对象然后再传。

望采纳

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

带参的intent是startActivityForResult(intent); 具体用法百度下吧,讲解清晰到位

Intent.putExtra传字符串
Intent.putInt传数值