Android 将值传递给另一个活动
我正在尝试以字符串格式将值0000002传递给下一个活动,如下所示:Android 将值传递给另一个活动,android,android-intent,android-activity,Android,Android Intent,Android Activity,我正在尝试以字符串格式将值0000002传递给下一个活动,如下所示: Intent pass = new Intent(this, SecondActivity.class); pass.putExtras("EmpID", "0000002"); 在第二个活动中 Bundle info = getIntent().getExtras(); System.out.println("Test " + info.getString("EmpID")); // this line printing
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtras("EmpID", "0000002");
在第二个活动中
Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID")); // this line printing "null" value instead of "0000002".
Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID"));
我能够成功地传递和获取其他字符串。我找不到EmpID
请帮帮我。这是一个样品
//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);
从第一次活动开始
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);
在活动中
String string1 = getIntent().getStringExtra("Loan Amount");
String string2 = getIntent().getStringExtra("Loan Tenture");
String string3 = getIntent().getStringExtra("Interest Rate");
对于您的情况,您可以使用like
Bundle localBundle = new Bundle();
localBundle.putString("EmpID", "0000002");
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtras(localBundle);
startActivity(pass);
在第二个活动中,您可以获得类似的EmpId
String empId = getIntent().getStringExtra("EmpID");
Bundle bundle = getIntent().getExtras();
String empId = bundle.getString("EmpID");
---------另一种方式---------
在第二个活动中,您可以获得类似的EmpId
String empId = getIntent().getStringExtra("EmpID");
Bundle bundle = getIntent().getExtras();
String empId = bundle.getString("EmpID");
这是一个样本
从第一次活动开始
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);
在活动中
String string1 = getIntent().getStringExtra("Loan Amount");
String string2 = getIntent().getStringExtra("Loan Tenture");
String string3 = getIntent().getStringExtra("Interest Rate");
对于您的情况,您可以使用like
Bundle localBundle = new Bundle();
localBundle.putString("EmpID", "0000002");
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtras(localBundle);
startActivity(pass);
在第二个活动中,您可以获得类似的EmpId
String empId = getIntent().getStringExtra("EmpID");
Bundle bundle = getIntent().getExtras();
String empId = bundle.getString("EmpID");
---------另一种方式---------
在第二个活动中,您可以获得类似的EmpId
String empId = getIntent().getStringExtra("EmpID");
Bundle bundle = getIntent().getExtras();
String empId = bundle.getString("EmpID");
写入pass.putextempid,0000002;非putExtras写入pass.putextrampid,0000002;不使用putExtras使用此
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");
startActivity(pass);
在第二个活动中
Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID")); // this line printing "null" value instead of "0000002".
Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID"));
用这个
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");
startActivity(pass);
在第二个活动中
Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID")); // this line printing "null" value instead of "0000002".
Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID"));
尝试使用以下方法:
传递值时:
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");
要获取值,请执行以下操作:
System.out.println("Test " + getIntent().getStringExtra("EmpID"));
尝试使用以下方法:
传递值时:
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");
要获取值,请执行以下操作:
System.out.println("Test " + getIntent().getStringExtra("EmpID"));
在SecondActivity中,这个Bundle info=getIntent.getExtras在哪里?您可以向我们展示更多的代码吗?将其他有效字符串发送到何处?将putExtra用于PutExtras的istead。在SecondActivity中是否有此捆绑包info=getIntent.getExtras?能否向我们展示更多代码?发送其他有效字符串的位置?使用putExtra作为putextrasYes的istead,它有putExtra方法。是的,它有putExtra方法。此答案有什么新内容?此答案有什么新内容?