I have two classes like firstactivity.java and secondactivity.java. In firstactivity I have a button(submit) when I click the button(submit) I want to pass the data of firstactivity.java to server. How can I do this?
Thanks in advance.
I have two classes like firstactivity.java and secondactivity.java. In firstactivity I have a button(submit) when I click the button(submit) I want to pass the data of firstactivity.java to server. How can I do this?
Thanks in advance.
In
FirstActivity.java
fileonclick
button you should used below code.In
secondActivity.java
file oncreate .. used below code.You can pass data from one activity to another activity by using this:
And you can get this data to secondActivity by using this:
But remember one thing: keyword would be same when you pass the data as well as getdata, for example:
You can use the putExtra(String name, Bundle value) method of Intent class to send data to second activity. Get this data in second activity from a Bundle object's getExtra() method.
For passing data between activities you could use set extra methods of intent which you use for starting activity link
Also you can use Bundle to pass data between parts of you program
You can return data from second activity to first using method setResult
You can add things to a bundle and add the bundle to the intent.
Then read the bundle in the new activity and get what you need from it. There should be hundreds of posts on Google and SO about this.
First send the second activity data to your first activity using intents,then get that data in First Activity using getIntent() method or you can store those data in static fields then you can get the data wherever you want