2016-04-30 97 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輕鬆存儲應用程序數據。

相關問題