我的應用程序出現問題。我正嘗試使用此代碼從活動轉移整數:如何將變量從文件傳輸到另一個
Intent intent = new Intent(context, Lesson.class);
Intent intent1 = new Intent(context, Example1.class);
switch(position){
case 0: {intent.putExtra("Title", l1);intent1.putExtra("check_cat", position);break;}
case 1: {intent.putExtra("Title", l2);intent1.putExtra("check_cat", position);break;}
case 2: {intent.putExtra("Title", l3);intent1.putExtra("check_cat", position);break;}
case 3: {intent.putExtra("Title", l4);intent1.putExtra("check_cat", position);break;}
case 4: {intent.putExtra("Title", l5);intent1.putExtra("check_cat", position);break;}
case 5: {intent.putExtra("Title", l6);intent1.putExtra("check_cat", position);break;}
第一個意圖有效,但第二個意圖不起作用。我沒有收到任何數據。這裏就是我處理信息的代碼:
final int[] pos_categ = new int[1];
pos_categ[0] = getIntent().getExtras().getInt("check_cat");
然後我嘗試使用它作爲一個條件的「if語句」:
if (pos_categ[0]==1){
title[0] = lessons_titles[position[0]];
eng[0] = eng_version[position[0]];
dan[0] = dan_version[position[0]].toLowerCase();
}
if (pos_categ[0]==2){
title[0] = lessons_titles2[position[0]];
eng[0] = eng_version2[position[0]];
dan[0] = dan_version2[position[0]].toLowerCase();
}
if (pos_categ[0]==3){
title[0] = lessons_titles3[position[0]];
eng[0] = eng_version3[position[0]];
dan[0] = dan_version3[position[0]].toLowerCase();
}...
我沒有得到任何錯誤,但是從應用程序是沒有通過if語句,因爲變量pos_categ [0]沒有任何值...有人可以幫我解決這個問題嗎?
但爲什麼兩個'Intent's?你是否將兩個「意圖」發送給一個「活動」? (這實際上是不可能的) – EdmDroid
我發送到兩個不同的活動。(Lesson.class和Example1.class) –
在你的文章中哪些代碼片段屬於哪個? – EdmDroid