gpt4 book ai didi

java - 如何将值从父 Activity 传递到子 Activity 以及在子 Activity 退出时刷新父 Activity

转载 作者:行者123 更新时间:2023-11-30 03:27:58 34 4
gpt4 key购买 nike

我有 3 个 Activity 。

  1. 主窗口 5 个按钮
  2. 在按钮的主窗口中按下此窗口打开(将其称为父窗口)
  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?

最佳答案

在 WIndow1 中:

开始你的 child Activity 作为

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();

protected void onActivityResult (int requestCode, int resultCode, Intent data)

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. The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.

关于java - 如何将值从父 Activity 传递到子 Activity 以及在子 Activity 退出时刷新父 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17937634/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com