简体   繁体   中英

How to Exchange Text between Screens in android app

While Developing of an Intent Android application. I want to insert data in main_actvity.java and get the same data in intent_activity.java(I want to insert data in activity_main.xml and get data in intent_test.xml)

Example: I want to login(With username and password) and display my username in next screen(after logging).

Using INTENT we can pass data from one Activity to another activity.

use INTENT for first Activity....

Intent i=new Intent(this, Next.class);//`this` is your class context and `Next.class` is another activity. 
i.putExtra("username",username.getText());
i.putExtra("password",password.getText());
startActivity(i);

use second Activity;

String username=getIntent().getStringExtra("username"),password=getIntent().getStringExtra("password");

Enjoy coding.....

You can use Intent as @Sushil suggested. Another way i can suggest is use of SharedPreferences . Google some good tutorials on using SharedPreferences for easy storage of app data.

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