检查一些遗留代码我发现了这个 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/