问题
I have the first intent, it starts the second intent. In the second intent, I get the values, and pass the value to the first content and close the second content. How can I do it?
回答1:
You can directly pass parameters to the intent when you create it. If you need to pass objects you need to implement Parcelable interface on the object you pass:
Intent i = new Intent(MyActivity.this, SecondActivity.class);
MyData j = new MyData();
i.putExtra("MyParameter", "Something");
i.putExtra("MyData", j); //only works if MyData implements Parcelable
startActivity(i);
In the second activity you can read your data:
Intent i = getIntent();
Bundle extras = i.getExtras();
if(extras.containsKey("MyParameter")) {
String something = i.getStringExtra("MyParameter");
}
if(extras.containsKey("MyData")) {
MyData otherthing = i.getParcelableExtra("MyData");
}
Hope this helps
回答2:
try this
Passing the parameter to using intent i am passing the message like this
Intent intent= new Intent(mContext,SuccessActivity.class);
intent.putExtra("message",mContext.getString(R.string.success_sign_msg));
Get value using intent
Intent intent=getIntent();
success_msg_txt.setText(intent.getStringExtra("message"));
try this it helps you
来源:https://stackoverflow.com/questions/51181747/passing-arguments-to-intent-android