您的位置:首页 > 移动开发 > Android开发

Intent数据传递两种常见方式

2017-07-25 10:39 369 查看
一、方法1:

//发送
Intent intent = new Intent(xxx.this, xxx.class);

Bundle bundle = new Bundle();
bundle.putString( "tag1", "aaa");
bundle.putInt("tag2", 22);
intent.putExtras( bundle );

startActivity( intent );

//接收
Intent intent = getIntent();

Bundle bundle = intent.getExtras();
String s = bundle.getString( "tag1" );
int i = bundle.getInt( "tag2" );

二、方法2:
//发送
Intent intent = new Intent(xxx.this, xxx.class);

intent.putExtra( "tag1", "aaa" );
intent.putExtra( "tag2", 2 );

startActivity( intent );

//接收
Intent intent = getIntent();

String s = intent.getStringExtra( "tag1" );
int i = intent.getIntExtra( "tag2" ); 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  笔记 android