1

I have an Activity -> MasterActivity and one more Activity ChildActivity which extends from 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:

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:

 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?

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

User3
  • 2,465
  • 8
  • 41
  • 84
  • the first answer here might help you: https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android – Naveen Niraula Mar 13 '19 at 02:50
  • Please refer from Android developer website https://developer.android.com/training/basics/intents/result that has the details guideline – Liem Vo Mar 13 '19 at 02:51
  • 1
    you guys misunderstood the question, the OP doesnt want to pass data to the activtiy that opened the ChildActivity, instead he wants to pass data to the MasterActivity which the ChildActivtiy is inheriting from. – Lorence Hernandez Mar 13 '19 at 03:00
  • Possible duplicate of [Sending data back to the Main Activity in Android](https://stackoverflow.com/questions/920306/sending-data-back-to-the-main-activity-in-android) – Adil Mar 13 '19 at 04:25
  • Are you using fragments? If so just use fragment arguments. – mtotowamkwe Mar 13 '19 at 22:11

1 Answers1

1

You could do this by getting your intent data directly from the MasterActivity#onCreate

You might also want to change the tag to kotlin instead of java.

Lorence Hernandez
  • 1,189
  • 12
  • 23
  • Can you provide a concrete example? Currently I am not launching an intent to master Activity I am launching an intent to ChildActivity and I further want to pass it to MasterActivity – User3 Mar 13 '19 at 03:24
  • As you see, `origUrl = intent.getStringExtra(EXTRA_URL)` in `onCreate` of `MasterActivity` is giving me an exception – User3 Mar 13 '19 at 03:25
  • Yes you are launching ChildActivity but MasterActivity will have access to your bundle since its also a child of Activity, you might want to read about inheritance. anw can you post the exception here? – Lorence Hernandez Mar 13 '19 at 03:35