我有兩個活動說X和Y.在x中有edittext n 6 radiobutton,如果用戶單擊按鈕,則根據edittext n radiobutton的輸入從數據庫中檢索值。這些值應該顯示在下一個活動y中。你可以幫助給片段..預先感謝如何從以前的活動中獲取新活動的結果會導致android?
1
A
回答
0
您可以輕鬆地從一個活動傳遞數據到另一個使用捆綁或意圖獲取傳遞的數據。
讓我們看看使用捆綁下面的例子:
//creating an intent to call the next activity
Intent i = new Intent("com.example.NextActivity");
Bundle b = new Bundle();
//This is where we put the data, you can basically pass any
//type of data, whether its string, int, array, object
//In this example we put a string
//The param would be a Key and Value, Key would be "Name"
//value would be "John"
b.putString("Name", "John");
//we put the bundle to the Intent
i.putExtra(b);
startActivity(i, 0);
在「NextActivity」你可以用下面的代碼檢索數據:
Bundle b = getIntent().getExtra();
//you retrieve the data using the Key, which is "Name" in our case
String data = b.getString("Name");
如何只使用意向來傳輸數據。讓我們看一下例子
Intent i = new Intent("com.example.NextActivity");
int highestScore = 405;
i.putExtra("score", highestScore);
在「NextActivity」你可以檢索數據:
int highestScore = getIntent().getIntExtra("score");
現在你會問我,什麼意圖和包之間的差別,他們好像 他們這樣做究竟一樣的東西。
答案是肯定的,他們都做同樣的事情。但是如果你想傳輸大量的數據,變量,大型數組,你需要使用Bundle,因爲它們有更多的方法來傳輸大量的數據(也就是說,如果你只傳遞一個或兩個變量,那麼只需要使用Intent。)
0
你應該把值放入一個包中,並將該包傳遞給開始下一個活動的意圖。示例代碼是在回答這個問題:Passing a Bundle on startActivity()?
0
綁定,你想與您所呼叫轉到下一個活動的意圖發送數據。
Intent i = new Intent(this, YourNextClass.class);
i.putExtra("yourKey", "yourKeyValue");
startActivity(i);
在YourNextClass活動,您可以通過使用
Bundle extras = getIntent().getExtras();
if (extras != null) {
String data = extras.getString("yourKey");
}
相關問題
- 1. 如何從以前的活動中獲得結果?
- 2. 如何從android中的Child活動獲取父項的結果?
- 3. 如何獲取Android上前臺活動的活動時間
- 4. 如何從WebService獲取顯示在Android活動上的結果?
- 5. Android - 在調用活動完成時獲取活動結果
- 6. android獲取當前前臺活動的活動對象
- 7. Android:如何從活動活動關閉前臺活動?
- 8. 移動到android中的活動組中的以前的活動
- 9. 如何通知當前活動從以前的活動
- 10. Android活動結果
- 11. 獲取從活動陸續結果
- 12. 如何從android中的IME服務獲取當前活動
- 13. ANDROID從以前的活動中獲取數據
- 14. 如何從以前的活動中獲取值
- 15. 當新活動開始時不會暗淡以前的活動
- 16. Android:從該活動中沒有完成呼叫的活動中獲得結果
- 17. Android的基本活動的onActivityResult()結果從子活動需要
- 18. Android活動完成更新以前的活動
- 19. 如何在父標籤活動中獲取子活動的結果?
- 20. 獲取的EditText從活動中的Android
- 21. 從小部件啓動的活動中獲取結果。
- 22. 從proccess啓動的活動中獲取結果CommandCompact
- 23. 如何關閉specefic活動並以編程方式獲取以前的活動?
- 24. 如何在android的另一個活動中獲取一個活動的更新?
- 25. 如何從Android上的多個活動中獲取運行線程的結果?
- 26. Android - 如何恢復以前的活動?
- 27. Android,獲得以前的活動狀態?
- 28. 如何獲取當前活動的活動?
- 29. 如何重新加載活動從Android在以前的狀態?
- 30. 如果從Overlay開始,如何從活動中獲得結果?
我有在遊標變量檢索值,然後如何通過? – Chetan