[英]How to pass value from parent activity to child activity and on child activity exit, refresh the parent activity
我有3个活动。
现在从子窗口中,我从父窗口中获得了价值,如下所示:
// Set - from Window1
Intent MyRotationsAddPicture1 = new Intent(getBaseContext(), MyRotationsAddPicture.class);
MyRotationsAddPicture1.putExtra("Title", "1");
MyRotationsAddPicture1.putExtra("Content", "2");
startActivity(MyRotationsAddPicture1);
// Get - from Window2
Log.d(TAG, getIntent().getExtras().getString("Title"));
// Workout and exit this Window2 > to go back Window1 and show the latest update on window1
this.finish();
System.exit(0);
但是现在,在子窗口上工作之后,我退出此窗口并返回到上一个父窗口。 转到那里后,如何刷新已修改并需要在父窗口中显示最新图像的imageView?
在Windows1中:
开始您的孩子活动
Intent MyRotationsAddPicture1 = new Intent(getBaseContext(), MyRotationsAddPicture.class);
MyRotationsAddPicture1.putExtra("Title", "1");
MyRotationsAddPicture1.putExtra("Content", "2");
startActivityForResult(MyRotationsAddPicture1, 0);
覆盖:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
在窗口2中:
// Get - from Window2
Log.d(TAG, getIntent().getExtras().getString("Title"));
// Workout and exit this Window2 > to go back Window1 and show the latest update on window1
setResult(0);
this.finish();
受保护的void onActivityResult(int requestCode,int resultCode,Intent数据)
在API级别1中添加。当您启动的活动退出时,会向您提供该密码,并向您提供启动它的requestCode,返回的resultCode以及其中的任何其他数据。 如果活动明确返回该结果,未返回任何结果或在其操作期间崩溃,则resultCode将为RESULT_CANCELED。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.