简体   繁体   中英

How to retrieve data from one Activity/Screen to another Activity/Screen in Android?

I have created a form in one activity (This form has some text views and edit text fields). Once I fill the form, say I accept and click on submit button I should get a new screen with all the fields that I have filled in the form and ask me for confirmation. After I click the confirm button it should end up in the another Activity/screen. Can anybody help me?

Thank you(In advance) Swetha

You can pass primitive data like strings etc. using intents as follows

String fName_temp   = "aaa";
String lName_temp   = "ccc";
String age_temp     = "12";
String address_temp = "test Address";

Intent i = new Intent(this, ToClass.class);
    i.putExtra("fname", fName_temp);
    i.putExtra("lname", lName_temp);
    i.putExtra("age", age_temp);
    i.putExtra("address", address_temp);
startActivity(i);   

Then in second activity you can get above intent using,

Intent i = getIntent();
String fName = i.getString("fname");

etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM