我对使用安卓工作室有点陌生,我的老师让我学习如何使用intent.getStringExtra和intent.putExtra。
请帮我解释一下这两件事。谢谢!
发布于 2018-08-19 05:12:42
通常,意图用于在某些android组件之间移动,比如(activity、service、广播接收器...etc) --您需要在这些组件之间传递一些值,因此您需要在发送方组件中使用put,在接收方中使用put,例如:
在发送者中:
Intent intent = new Intent(SenderActrivtiy.this, REciverActivity.class);
intent.putExtra("emailKey", "mm@email.com");
startActivity(intent);
在reciver中:
String email =getIntent().getStringExtra("emailKey");
注意,您需要传递相同的键来检索您的值。
https://stackoverflow.com/questions/51917897
复制