android - Android Activity 可以在 finish() 之后恢复吗?

标签 android android-activity android-lifecycle

检查一些遗留代码我发现了这个 fragment :

@Override
public void onResume() {
    if (!isFinishing()) {
        ...
    }
    super.onResume();
}

尽管在方法末尾调用了 super.onResume(),这是不鼓励的:

Note: Your implementation of these lifecycle methods must always call the superclass implementation before doing any work, as shown in the examples above http://developer.android.com/guide/components/activities.html

我担心 if (!isFinishing()) 调用,这有意义吗?如我所见,检查 Activity 代码 mFinished 变量仅在 finish()finishActivity() 上设置为 true,可以通过 Android 生命周期, 要恢复正在销毁的 Activity ?

提前致谢。

最佳答案

最后,在某些情况下,遗留代码在 onCreate() 方法中调用了 finish()。但是看看 onCreate() javadoc :

You can call finish() from within this function, in which case onDestroy() will be immediately called without any of the rest of the activity lifecycle (onStart(), onResume(), onPause(), etc) executing.

因此,这个 isFinishing() 调用在 onResume() 中是无用的

关于android - Android Activity 可以在 finish() 之后恢复吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29849259/

相关文章:

android - 应用程序在后台被杀死时的应用程序生命周期

android - 如何在android中读取XML父节点标签值

android - 尝试使用服务暂停/恢复音乐 Activity

android - 使用 onSaveInstanceState 保存列表数据对象

android - 使用接口(interface)和方法 onAttach(Fragments)

android - onCreate 启动两次,没有任何 UI 更改

java - 用于隐藏软件键盘的KeyEvent代码?

android - 如何保存先前选择的单选按钮状态,并在应用程序退出和启动时始终处于第一个选择状态?

java - 如何更改 ViewPager 幻灯片上 fragment 的内容?

android - 在 onPause 而不是 onDestroy 中释放资源