本文介紹了如何將整數從一個活動傳遞到另一個活動?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想將一個整數的新值從一個活動傳遞到另一個活動.即:
I would like to pass a new value for an integer from one Activity to another. i.e.:
活動 B 包含一個
integer[] pics = { R.drawable.1, R.drawable.2, R.drawable.3}
我希望活動 A 將新值傳遞給活動 B:
I would like activity A to pass a new value to activity B:
integer[] pics = { R.drawable.a, R.drawable.b, R.drawable.c}
所以通過某種方式
private void startSwitcher() {
Intent myIntent = new Intent(A.this, B.class);
startActivity(myIntent);
}
我可以設置這個整數值.
I can set this integer value.
我知道這可以通過捆綁包以某種方式完成,但我不確定如何將這些值從活動 A 傳遞到活動 B.
I know this can be done somehow with a bundle, but I am not sure how I could get these values passed from Activity A to Activity B.
推薦答案
很簡單.在發送方,使用 Intent.putExtra
:
It's simple. On the sender side, use Intent.putExtra
:
Intent myIntent = new Intent(A.this, B.class);
myIntent.putExtra("intVariableName", intValue);
startActivity(myIntent);
在接收方,使用 Intent.getIntExtra
:
On the receiver side, use Intent.getIntExtra
:
Intent mIntent = getIntent();
int intValue = mIntent.getIntExtra("intVariableName", 0);
這篇關于如何將整數從一個活動傳遞到另一個活動?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!