kotlin - 我怎样才能将苛刻的地图传递给 Kotlin 上的另一个活动?
问题描述
我一直在使用 Firestore 开发数据库。数据库本身正在工作,但是当我尝试从harshMap 中获取值时,我得到一个空值,尽管我可以看到数据库(在页面上)显示了我想要获取的参数。
所以我的问题是下一个问题:是否有适当的方法从另一个活动中的harshMap 中获取值?
代码中有一些注释,请看一下。
活动“A”上的 setup()
private fun setup(){
crearCuentaButton.setOnClickListener{
if (inputEmail.text.isNotEmpty() && inputContraseña.text.isNotEmpty()){
val db = FirebaseFirestore.getInstance()
val userData = hashMapOf(
"username" to inputUsername.text.toString(),
"email" to inputEmail.text.toString()
)
db.collection("users")
.add(userData)
FirebaseAuth.getInstance().createUserWithEmailAndPassword(inputEmail.text.toString(), inputContraseña.text.toString()) .addOnCompleteListener {
if(it.isSuccessful){
showAuth(it.result?.user?.email ?: "", ProviderType.Email)
}
else{
showError()
}
}
Intent(this, HomeActivity::class.java).also {
val userName = userData["username"]
println(userName)
it.putExtra("dataBaseUsernameValue", userName) //<------ this is the value I'm trying to get, the println shows the variable perfectly, but when passing it through, it doesn't.
}
}
}
}
在活动“B”上创建
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
homeBanner()
val username = intent.getStringExtra("dataBaseUsernameValue")
println(username) //<----------------- here I get the "null"
}
解决方案
推荐阅读
- python-3.x - 如何在不使用 cov 和 corr 的情况下计算 Python 中的协方差和相关性?
- oop - 非抽象类的非空方法和抽象方法的抽象方法的好处?
- mysql - 在基于 MySQL 中另一个字段的子查询中使用 LIMIT
- java - 绑定没有正确更新
- api - Yii2:未发送 HttpClient 授权标头
- javascript - 从 TypeScript 中的状态解构值时出错
- sql-server - 使用行到列转换连接表
- git - 我应该使用 gitignore 还是“your-api-key-here”来隐藏 Github 上的 api 密钥?
- http - 如何使用套接字分别发送 HTTP 标头和 HTTP 正文?
- python - SQL Server 机器学习调用外部 REST API