开发者

how to recieve the second activity intent on first activity

开发者 https://www.devze.com 2023-03-04 22:36 出处:网络
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开发者_如何转开发s

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消