我有一个适配器,我强制转换了MainActivity
传递的上下文,这里是Adapter
代码
class Adapter {
....
....
inner class ViewHolder (view: View) : RecyclerView.ViewHolder(view) {
init {
val intent = Intent((context as MainActivity), FooActivity::class.java)
context.startActivityForResult(intent, FROM_FOO_ACTIVITY)
}
}
然后在FooActivity
val intent = Intent()
setResult(Activity.RESULT_OK, intent)
finish()
然后在MainActivity
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK && requestCode == FROM_FOO_ACTIVITY) {
//do my thing
}
}
问题是没有到达onActivityResult,我的方法有什么问题?