2017-04-27 3 views
0

나는 번들을 생성하고 그 값을 다음 액티비티로 옮겼다. 어떤 이유로 다른 끝에서 값을 얻을 수 없다. 다른 활동에서안드로이드에서 하나의 액티비티에서 다른 액티비티로 값을 보낼 수 없다.

public void rsa_key(String s){ 
     Intent intent = new Intent(getBaseContext(), SomeClass.class); 
     //Create the bundle 
     Bundle bundle = new Bundle(); 

//Add your data to bundle 
     //String hello=null; 
     bundle.putString("id", txId); 
     bundle.putString("cardamt", cardAmount); 
     bundle.putString("cardconv", cardConvFee); 
//Add the bundle to the intent 
     intent.putExtras(bundle); 




     startActivity(intent); 

    } 

를 참조 객체,하지만 난 나와 함께 내 값이

String txId = bundle.getString("id"); 
     String cardConvFee = bundle.getString("cardconv"); 
     String cardAmount = bundle.getString("cardamt"); 
+0

다른 활동에있는 코드는 어디에 있습니까? inCreate에서. 또한 디버거를 사용하면 도움이됩니다 – Raghunandan

+0

두 번째 활동에서 첫 번째 활동 번들을 어떻게 얻고 있습니까? 로그를 올리시기 바랍니다. –

+0

나는 그것을 OnCreate 외부에 넣었습니다. 그게 문제라고 생각합니다. – Venky

답변

4

이 시도 :

public void rsa_key(String s){ 
     Intent intent = new Intent(getBaseContext(), SomeClass.class); 

     //String hello=null; 
     intent.putExtras("id", txId); 
     intent.putExtras("cardamt", cardAmount); 
     intent.putExtras("cardconv", cardConvFee); 





     startActivity(intent); 

    } 
두 번째 활동

에서 onCreate 방법

Bundle bundle = getIntent().getExtras(); 
String txId = bundle.getString("id"); 
     String cardConvFee = bundle.getString("cardconv"); 
     String cardAmount = bundle.getString("cardamt"); 
+0

업데이트 된 응답을 확인하십시오 –

+0

아, OnCreate 안에 있어야합니까 ?? – Venky

+0

예 .................. –

0

첫 번째 문자열에서 정수 값을 변환 한 다음 다른 활동으로 보내 주시기 바랍니다.

 Bundle bundle = new Bundle(); 

     //Add your data to bundle 
     //String hello=null; 
     bundle.putString("id", String.valueOf(txId)); 
     bundle.putString("cardamt", String.valueOf(cardAmount)); 
     bundle.putString("cardconv", String.valueOf(cardConvFee));