led*_*edy 6 android destroy android-lifecycle
在覆盖活动的ondestroy时,我应该在super.onDestroy()之前或之后放置命令吗?
protected void onDestroy() {
//option 1: callback before or ...
super.onDestroy();
//option 2: callback after super.onDestroy();
}
Run Code Online (Sandbox Code Playgroud)
(现在我担心:如果super.onDestroy太快,它将永远不会到达选项2.)
这就是当你调用 super.onDestroy(); 时会发生的情况。
protected void onDestroy() {
mCalled = true;
// dismiss any dialogs we are managing.
if (mManagedDialogs != null) {
final int numDialogs = mManagedDialogs.size();
for (int i = 0; i < numDialogs; i++) {
final Dialog dialog = mManagedDialogs.valueAt(i);
if (dialog.isShowing()) {
dialog.dismiss();
}
}
}
// also dismiss search dialog if showing
// TODO more generic than just this manager
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchManager.stopSearch();
// close any cursors we are managing.
int numCursors = mManagedCursors.size();
for (int i = 0; i < numCursors; i++) {
ManagedCursor c = mManagedCursors.get(i);
if (c != null) {
c.mCursor.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
本质上,这意味着在代码之前或之后调用它并不重要。
| 归档时间: |
|
| 查看次数: |
16439 次 |
| 最近记录: |