email - 有没有办法通过 ViewModel 使用 Live Data 启动活动电子邮件?
问题描述
我知道您不能将活动或片段作为参数传递给视图模型,并且为了通过点击事件启动事件或更新 UI,最好使用 LiveData。但是,我不知道如何使用 LiveData 启动电子邮件活动。就我而言,您无法在类视图模型上启动活动。这是我拥有的代码。(评论中的行只是一个例子,我知道他们不会为此工作)。
MainActivity.kt
val obvserver = Observer<String> {studentEmail.setOnClickListener{ intent = Intent(Intent.ACTION_SEND)
intent.data = Uri.parse("mailto:")
intent.type = "message/rfc822"
intent.putExtra(Intent.EXTRA_EMAIL, selectedStudent.email)
startActivity(Intent.createChooser(intent, "Send Email"))}}
studentEmail.setOnClickListener {
//viewModel.
}
ViewModel.kt
val studentEmail : MutableLiveData<String> by lazy {
MutableLiveData<String>()}
解决方案
推荐阅读
- csv - 使用 SAVE TRANSLATE 导出为 CSV,但空值导出为单个空格
- machine-learning - Pyspark 训练的 Logistic 回归模型没有 predict() 和 predictProbability() 函数
- julia - Julia 宏观卫生的载体
- opendaylight - 由于 ietf-netconf@2011-06-01.yang 版本不兼容,ietf-netconf 操作失败,我们如何使其工作?
- java - 在 java 中创建子数组是否使用 O(1) 额外空间
- python - 雪花截断被回滚
- tensorflow - 将 BERT pytorch 模型转换为 TF 检查点
- jpa - 如何根据作为另一个属性的 id 指定 JPA ManyToOne 关系
- docker - 在 Windows 容器内运行电报
- reactjs - 如何抑制来自@testing-library/react 的错误输出?