2010-03-21 78 views
2

我已經通讀了Android Dev Guid (http://developer.android.com/guide/appendix/faq/commontasks.html#opennewscreen的常見問題解答),但我不確定如何使用傳入的其他參數打開新屏幕。如何使用其他參數打開新屏幕?

比方說,我打算打開screen2,並顯示一個變量,指出當前用戶名,以便我可以迎接用戶。可能嗎?

Intent i; 
i = new Intent(this, screen2.class); 
//How to pass variable to screen2? 
startActivity(i); 

回答

4

開始意圖通過:

Intent foo = new Intent(this, viewContactQuick.class); 
     foo.putExtra("id", id); 
     this.startActivity(foo);  

,並在OnCreate事件就可以得到id

id = this.getIntent().getLongExtra("id", 0); 
0

從你有的鏈接中查找putExtra

putExtra方法(來自Intent對象)用於在活動之間傳遞數據。

要將數據發送到其他活動,請使用putExtra

從另一個活動接收數據,使用getExtra

一個short description to read

2

使用putExtra方法。喜歡的東西:

Intent i = new Intent(this, myNew.class); 
i.putExtra("key",keyValue); 

,並在另一側只,吸氣:

this.getIntent().getIntExtra("key"); // If keyvalue was an int 
相關問題