簡體   English   中英

如何設置一個意圖,以便我可以將數據發送到第二個活動,然后從那里發送到第三個活動?

[英]How to set an intent so that I can send a data to the second activity and from there to the third activity?

我在第一個活動中從用戶那里得到輸入,然后將其發送到第二個活動。 在第二個活動中,使用用戶輸入,我從數據庫中獲取數據,並希望將該數據發送到第三個活動。 從第二個活動到第三個活動,我如何給出意圖?

大概您是使用Intent開始每個活動的,在這種情況下,您可以額外傳遞數據。

Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.putExtra("user_input_key", "user_input");
startActivity(i);

在第二個活動中,onCreate

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String userInput = extras.getString("user_input_key");
    //Once activity starts use this string to get data from DB and put/get extra in the same way
}

您不應該在活動之間傳遞意圖。 准確確定您要在活動之間傳遞的內容,並將這些數據作為額外的意圖放入並在新的Activity onCreate中檢索該數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM