一.ActivityA跳转ActivityB及传值返回
1. ActivityA 跳转
Intent intent = new Intent(this, ActivtyB.class);
startActivityForResult(intent, REQUEST_SELECT);
2.ActivityA onActivityResult 获取返回结果
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_SELECT&& resultCode == RESULT_OK) {
String name = data.getStringExtra("name");
}
}
3 ActivityB带值返回
Intent data = new Intent();
data.putExtra("name", "name");
setResult(RESULT_OK, data);
finish();
二.FragmentA跳转ActivityC及传值返回
1.FragmentA 跳转
Intent intent = new Intent(getActivity(), ActivityC.class);
intent.putExtra("setting_money", money);
startActivityForResult(intent,REQUEST_SETTING_MONEY);
2. FragmentA onActivityResult获取返回结果
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_SETTING_MONEY && resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
money = bundle.getString("setting_money_result");
}
}
3 ActivityC带值返回
获取FragmentA传递的值
money = getIntent().getStringExtra("setting_money");
ActivityC带值返回
Bundle bundle = new Bundle();
bundle.putString("setting_money_result", currentSettingMoneyNew);
setResult(RESULT_OK, this.getIntent().putExtras(bundle));
finish();
今天的文章Activity 跳转及传值返回分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/32542.html