Android Activity 可以在 finish() 之后恢复吗?
Can an Android Activity be resumed after finish()?
检查一些遗留代码我发现了这个片段:
@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 哪个正在被摧毁?
提前致谢。
你问题的答案是"no"activity销毁无法恢复
这是很好的讨论:
Understanding of isFinishing()
The reason for this code may be to distinguish between orientation
change and actual finishing of the activity Important to note here
is isFinishing: true which means that call to isFinishing()
in the
onDestroy() returns true, i.e. which happens when:
User hits "back" button OR activity's code calls it's finish()
(isFinishing()
returns false when activity is geting closed after
phone rotaion in order to be started again)
http://ogrelab.ikratko.com/activity-lifecycle-explained-in-details/
最后,遗留代码在某些情况下在 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()
内部无用
检查一些遗留代码我发现了这个片段:
@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 哪个正在被摧毁?
提前致谢。
你问题的答案是"no"activity销毁无法恢复
这是很好的讨论:
Understanding of isFinishing()
The reason for this code may be to distinguish between orientation change and actual finishing of the activity Important to note here is isFinishing: true which means that call to
isFinishing()
in the onDestroy() returns true, i.e. which happens when:User hits "back" button OR activity's code calls it's
finish()
(isFinishing()
returns false when activity is geting closed after phone rotaion in order to be started again)
http://ogrelab.ikratko.com/activity-lifecycle-explained-in-details/
最后,遗留代码在某些情况下在 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()