1

I am trying to pass value "0000002" in string format to next activity like below:

Intent pass = new Intent(this, SecondActivity.class);
pass.putExtras("EmpID", "0000002");

In second activity

Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID")); // this line printing "null" value instead of "0000002". 

I am able to pass and fetch the other strings successfully. I am not able to fetch the EmpID.

Please help me.

4

5 に答える 5

7

ここにサンプルがあります

最初の活動から

Bundle localBundle = new Bundle();
localBundle.putString("Loan Amount", editText1.getText().toString());
localBundle.putString("Loan Tenture", editText2.getText().toString());
localBundle.putString("Interest Rate", editText3.getText().toString());
Intent localIntent = new Intent(this, Activity2.class);
localIntent.putExtras(localBundle);
startActivity(localIntent);

そしてActivity2で

String string1 = getIntent().getStringExtra("Loan Amount");
String string2 = getIntent().getStringExtra("Loan Tenture");
String string3 = getIntent().getStringExtra("Interest Rate");

あなたの場合、次のように使用できます

Bundle localBundle = new Bundle();
localBundle.putString("EmpID", "0000002");
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtras(localBundle);
startActivity(pass);

SecondActivity では、次のように EmpId を取得できます

String empId = getIntent().getStringExtra("EmpID");


-----------------別の方法-----------------

Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");
startActivity(pass);

2 番目のアクティビティでは、次のように EmpId を取得できます

Bundle bundle = getIntent().getExtras();
String empId = bundle.getString("EmpID"); 
于 2013-09-27T12:12:32.643 に答える
1

これを使って

Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");
startActivity(pass);

2回目の活動で

Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID")); 
于 2013-09-27T12:16:39.987 に答える
1

書いpass.putExtra("EmpID", "0000002");てはいけませんExtras

于 2013-09-27T12:14:13.740 に答える
0

これを使ってみてください: 値を渡すとき:

Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");

値を取得するには:

System.out.println("Test " + getIntent().getStringExtra("EmpID"));
于 2013-09-28T08:51:06.713 に答える
0
//Activity A
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");

//Activity B
Intent intent = getIntent();
String EmpID = intent.getStringExtra("EmpID");
System.out.println("Test " + EmpID);
于 2013-09-27T12:08:07.240 に答える