本文介绍了尽管使用FLAG_ACTIVITY_REORDER_TO_FRONT调用了onCreate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个活动(A和B),并且有2个按钮可以切换.

I have 2 activities (A and B) and they have 2 buttons to switch between.

  1. 一个oncreate
  2. B oncreate
  3. 创建时
  4. 简历

我想要做的是从B向A发送意图之后,oncreate不应被调用,但此时它可以被调用.为了克服这个问题,我找到了FLAG_ACTIVITY_REORDER_TO_FRONT(从这里 ),并认为它只能调用onresume,但是没有.

what I wanted to do is after sending intent from B to A oncreate should not be called but at this point it does. To overcome that I found FLAG_ACTIVITY_REORDER_TO_FRONT (from here) and thought it could called only onresume but it didn't.

推荐答案

FLAG_ACTIVITY_REORDER_TO_FRONT 确实会执行您认为应该做的事情.但是,如果先启动 ActivityA ,然后 ActivityA 启动 ActivityB 并对其本身调用 finish(),则当 ActivityB 以具有 FLAG_ACTIVITY_REORDER_TO_FRONT 的Intent启动 ActivityA ,不会出现 ActivityA 的实例.在这种情况下,Android将仅创建一个新的.我只能假设这就是您所看到的.

FLAG_ACTIVITY_REORDER_TO_FRONT does exactly what you think it should do. However, if you start ActivityA and then ActivityA starts ActivityB and calls finish() on itself, then when ActivityB starts ActivityA with an Intent that has FLAG_ACTIVITY_REORDER_TO_FRONT there will be no instance of ActivityA to bring to the front. In this case Android will simply create a new one. I can only assume that is what you are seeing.

这篇关于尽管使用FLAG_ACTIVITY_REORDER_TO_FRONT调用了onCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 19:56