2016-04-30 41 views
0

开发意图Android应用程序时。我想在main_actvity.java中插入数据并在intent_activity.java中获取相同的数据(我想在activity_main.xml中插入数据并在intent_test.xml中获取数据)如何在Android应用程序屏幕之间交换文本

示例:我想登录(使用用户名和密码),并在下一个屏幕(登录后)显示我的用户名。

+1

你应该自己试一下,先找出问题,然后再问问题。 http://stackoverflow.com/a/4967833/4489552 –

+0

这有几个选项。告诉我你是否需要在活动被杀后保存数据。 –

回答

1

使用INTENT,我们可以将数据从一个活动传递到另一个活动。

使用意向为第一活动....

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); 

使用第二活性;

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

享受编码.....

0

您可以使用意向作为@Sushil建议。我建议的另一种方法是使用SharedPreferences。谷歌一些很好的教程使用SharedPreferences轻松存储应用程序数据。

相关问题