简体   繁体   English

如何将数据作为意图从子活动传递到父活动

[英]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.

相关问题 如何将值从父级活动传递到子级活动,以及如何在子级活动退出时刷新父级活动 - How to pass value from parent activity to child activity and on child activity exit, refresh the parent activity 无法通过 Intent 从子活动(谷歌地图)向父活动传递价值 - Unable to pass value through Intent from Child Activity (Google Maps) to Parent activity 如何将意图从 TabActivity 传递给其子活动 - How to pass intent from TabActivity to its child activity 如何将数据从Child Activity发送到android中的Parent Activity? - How to send data from Child Activity to Parent Activity in android? 如何从片段到父活动获取数据并将其传递给后台活动? - How to get data from fragment to parent activity & pass it to back activity? 将数据从子活动传递到父活动 - Pass data from sub activity to parent activity 如何从儿童活动中完成父活动 - How to finish parent activity from child activity 如何在无意中将数据从适配器传递到活动 - How to pass data from adapter to activity without intent 如何在Intent中传递一个Activity - How to pass an Activity in an Intent 将数据从 Activity 传递到带有 Intent 的广播接收器 - Pass data from Activity to Broadcast Receiver with Intent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM