gpt4 book ai didi

安卓 Activity 流程

转载 作者:行者123 更新时间:2023-11-29 18:11:57 28 4
gpt4 key购买 nike

我有两个 Activity ,比如 A1 和 A2。顺序为 A1->A2我从 A1 开始 A2 而没有在 A1 中调用 finish() 。在 A2 中按下后退按钮后,我想在 A1 中触发一个功能。但是,如果我在 A1 中使用 onResume(),即使在 Activity A1 开始时也会触发该函数,我想避免这种情况。它应该只在 A2 的“后退”按下期间被调用。

最佳答案

我们用 startActivityForResult 开始 A2 然后在

A1 实现

  @Override
public void onActivityResult(final int requestCode, int resultCode, final Intent data) {

// your code here

}

在 A2 中覆盖 onBackPresset 以在完成 Activity 之前设置结果。就是这样。

关于安卓 Activity 流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189044/

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