美文网首页Android
安卓代码段--传递Bundle数据

安卓代码段--传递Bundle数据

作者: tea9 | 来源:发表于2016-08-31 10:16 被阅读67次

    Intent intent=new Intent(MainActivity.this,TestAcitvity.class);
    Bundle bundle=new Bundle();
    bundle.putString("name","shaomiao");
    bundle.putInt("age",17);
    ///////
    intent.putExtras(bundle);
    startActivity(intent);


    Intent i=getIntent();
    ///////////
    Bundle bundle=i.getExtras();
    TextView textView= (TextView) findViewById(R.id.textView);
    textView.setText(String.format("name%s,age%d",bundle.getString("name"),bundle.getInt("age")));


    第二种:
    Intent intent=new Intent(MainActivity.this,TestAcitvity.class);
    Bundle bundle=new Bundle();
    bundle.putString("name","shaomiao");
    bundle.putInt("age",17);
    ////////
    intent.putExtra("data",bundle);
    startActivity(intent);


    Intent i=getIntent();
    Bundle bundle=i.getBundleExtra("data");
    TextView textView= (TextView) findViewById(R.id.textView);
    textView.setText(String.format("name%s,age%d",bundle.getString("name"),bundle.getInt("age")));

    相关文章

      网友评论

        本文标题:安卓代码段--传递Bundle数据

        本文链接:https://www.haomeiwen.com/subject/uzzfettx.html