[英]How to pass value from parent activity to child activity and on child activity exit, refresh the parent activity
I have 3 activity. 我有3个活动。
Now from child window I get value from parent window as below: 现在从子窗口中,我从父窗口中获得了价值,如下所示:
// 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);
But now, after working out on child window, I exit this and go back to my previous parent window. 但是现在,在子窗口上工作之后,我退出此窗口并返回到上一个父窗口。 Once I go there, how can I refresh my imageView which have been modified and need to show the latest image in parent window?
转到那里后,如何刷新已修改并需要在父窗口中显示最新图像的imageView?
In WIndow1: 在Windows1中:
Start your child activity as 开始您的孩子活动
Intent MyRotationsAddPicture1 = new Intent(getBaseContext(), MyRotationsAddPicture.class);
MyRotationsAddPicture1.putExtra("Title", "1");
MyRotationsAddPicture1.putExtra("Content", "2");
startActivityForResult(MyRotationsAddPicture1, 0);
Override: 覆盖:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
In window 2: 在窗口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();
protected void onActivityResult (int requestCode, int resultCode, Intent data)
受保护的void onActivityResult(int requestCode,int resultCode,Intent数据)
Added in API level 1 Called when an activity you launched exits, giving you the requestCode you started it with, the resultCode it returned, and any additional data from it.
在API级别1中添加。当您启动的活动退出时,会向您提供该密码,并向您提供启动它的requestCode,返回的resultCode以及其中的任何其他数据。 The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.
如果活动明确返回该结果,未返回任何结果或在其操作期间崩溃,则resultCode将为RESULT_CANCELED。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.