Reputation:
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?
Upvotes: 2
Views: 5768
Reputation: 9225
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
Upvotes: 0
Reputation: 6093
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
Upvotes: 1