Android Avtivity之间传值概述

(1)传出

Activity之间一般用intent传值,为了更加简化,我使用bundle存值,intent传bundle的方式传值。

首先,新建intent和bundle(这里的 showRegMsg 是目标activity的名称)

Intent intent = new Intent(this, showRegMsg.class);
Bundle bundle = new Bundle();

然后,在bundle里面放键值对,也就是要传递的数据。

bundle.putString("usrn",username);
bundle.putString("pswd",password1);
bundle.putString("sex", sex);
bundle.putString("sr",income);
bundle.putString("ah",hobby);
bundle.putString("beizhu",addition);

比如第一个,它的键是usrn,值为username这个变量的值,username是用户输入的字符串。

最后,startActivity(intent); 即可start目标activity并传递intent到目标activity

intent.putExtras(bundle);
startActivity(intent);

(2)接收

写在目标activity里面。

新建intent来接收传递过来的intent

Intent intent = getIntent();
Bundle bundle = intent.getExtras();

然后,通过键获取值。

String usrn=bundle.getString("usrn");
String pswd=bundle.getString("pswd");
String sex=bundle.getString("sex");
String sr=bundle.getString("sr");
String ah=bundle.getString("ah");
String beizhu=bundle.getString("beizhu");

END

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇