i have created two activities,first activity comes and goes to second page i.e. to second activity,and second activity goes on first,what i wanted is that when 2 activity goes to fir开发者_如何转开发st it has some data that to display in first activity.how can i do this please help.thanks in advance.
Just a sample code:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putInt("key", 1);
intent.putExtras(b);
startActivity(intent);
finish();
After it, we can get this data in a second activity:
Bundle b = getIntent().getExtras();
int value = b.getInt("key", 0);
You can return result to 1st activity. Refer to this .
As mentioned: Consider Activity1 calling startActivityForResult
. In Activity 2 call setResult
and immediately call finish()
. Back in Activity1 capture the return values in onActivityResult
.
精彩评论