gpt4 book ai didi

android 生命周期 onActivityResult 与 onStop

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:00:54 25 4
gpt4 key购买 nike

如果 Activity A 为结果启动 Activity B,我的印象是 Activity B 的 onStop 方法在 Activity A 的 onActivityResult 方法之前被调用。为什么不是这样?我刚刚使用 B.onStop 中设置的静态变量对其进行了测试,但是当我在 A.onActivityResult 中读取它时,该变量一直为 null。

最佳答案

我认为您想做的是调用 onPause,但是,您不想在那里做太多事情。 Here is what the docs say :

protected void onPause () Added in API level 1

Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. The counterpart to onResume().

When activity B is launched in front of activity A, this callback will be invoked on A. B will not be created until A's onPause() returns, so be sure to not do anything lengthy here.

This callback is mostly used for saving any persistent state the activity is editing, to present a "edit in place" model to the user and making sure nothing is lost if there are not enough resources to start the new activity without first killing this one. This is also a good place to do things like stop animations and other things that consume a noticeable amount of CPU in order to make the switch to the next activity as fast as possible, or to close resources that are exclusive access such as the camera.

关于android 生命周期 onActivityResult 与 onStop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15883754/

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