[英]How to pass data as intent from child activity to parent activity
I have an Activity -> MasterActivity and one more Activity ChildActivity which extends from Master Activity 我有一个活动-> MasterActivity和另一个活动ChildActivity,它是从Master Activity扩展而来的
Now the author of Master activity is expecting some values to come with the intent and parses these in the onCreate of Master activity: 现在,Master活动的作者期望一些意图附带价值,并在onCreate of Master活动中解析这些值:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_view)
origUrl = intent.getStringExtra(EXTRA_URL)
if (origUrl == null) throw RuntimeException("did you forget to put extras?")
}
And I start the intent to my ChildActivity like: 然后,我开始进行ChildActivity的意图:
context?.startActivity(Intent(context, TerminationWebview::class.java).apply {
putExtra(ChildActivity.EXTRA_URL, it)
Now the question is how do I pass this data to parent? 现在的问题是如何将这些数据传递给父级? So that parent can parse it in onCreate?
这样父级可以在onCreate中解析它?
This question does not deal with returning data from an activity, it deals with passing the data to parent activity through intent and hence is not . 这个问题不涉及从活动返回数据,而是通过意图将数据传递给父活动,因此不是。 a duplicate
重复的
You could do this by getting your intent data directly from the MasterActivity#onCreate
您可以通过直接从
MasterActivity#onCreate
获取意图数据来完成此操作
You might also want to change the tag to kotlin instead of java. 您可能还想将标签更改为kotlin而不是java。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.