The main activity includes some variables with set values. I created a sub-activity with the form which has to be filled with the data from main activity so I guess the data have to be passed to the sub-activity when it starts.
Does anyone know how to pass the variable values to the sub-activity from the main activity?
Thanks!
We can send the data using the putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.
putExtra() : This method sends the data to another activity and in parameter, we have to pass key-value pair. Add the below code in onClick() method. intent. putExtra("full_name", fullName);
You can pass the value in 2 ways: Either you make a global Class and set the value in that class and access that class in your 3rd activity. You can use Intent to send your values from 1st activity to 2nd activity.
You can use this method in your main activity
Intent i = new Intent(this, YourMainClass.class);
i.putExtra("key", value);
end then in the sub activity get the value with this method, usually in the onCreate event
int value = getIntent().getExtras().getInt("key");
I hope this hepls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With