sách gpt4 ai đã đi

Cách truyền giá trị từ hoạt động cha sang hoạt động con và làm mới hoạt động cha khi hoạt động con thoát

In lại 作者:行者123 更新时间:2023-11-30 03:27:58 35 4
mua khóa gpt4 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?

1 Câu trả lời

在 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/

35 4 0
Bài viết được đề xuất: android - 抽屉导航中的 Google Play 图书使用什么字体?
Bài viết được đề xuất: java - 通过 PHP 插入 SQL 数据库
Bài viết được đề xuất: java - INSERT OR IGNORE 插入重复语句
Bài viết được đề xuất: android - 如何显示 Android 中正在变化的变量?
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com