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

2022-07-15 13:33:21 浏览数 (1)

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”)));

0 人点赞