2014-03-31 2 views
-2

내 앱에 문제가 있습니다. 이 코드를 사용하여 작업에서 정수를 전송하려고합니다.변수를 파일에서 다른 것으로 전송하는 방법

  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(); 
    }... 

내가 오류를 얻을 해달라고하지만 응용 프로그램에서입니다 여기가 정보를 처리하는 코드는 변수 pos_categ [0]에 값이 없으므로 if 문을 사용하지 않습니다. 누군가이 문제를 해결할 수 있습니까?

+1

그런데 왜이'Intent's :

final int pos_categ = getIntent().getExtras().getInt("check_cat"); 
EdmDroid

+0

두 가지 다른 활동으로 보냅니다. (Lesson.class 및 Example1.class) –

+0

코드 스 니펫이 속한 게시물에 어떤 것이 있습니까? – EdmDroid

답변

1

먼저 두 가지 작업을 수행해야합니다.

Intent intent = getIntent(); 
if(intent.hasExtra("check_cat")) 
{ 
// your code 
} 

초 정수를 int로 사용해야합니다.

Intent intent = getIntent(); 
int pos_categ = 0; 
if(intent.hasExtra("check_cat")) { 
    pos_categ = intent.getExtras().getInt("check_cat"); 
} 
0

final int[] post_categ = new int[] {getIntent().getExtras().getInt("check_cat")}; 

더 나은 방법을 시도? 하나의 '활동'에 두 개의 '의도'를 보냅니 까? (실제로 불가능합니다)

관련 문제