Android初学者:onDestroy

前端之家收集整理的这篇文章主要介绍了Android初学者:onDestroy前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在覆盖活动的ondestroy时,我应该在super.onDestroy()之前或之后放置命令吗?
protected void onDestroy() {

    //option 1: callback before or ...

    super.onDestroy();

    //option 2: callback after super.onDestroy();
}

(现在我担心:如果super.onDestroy太快,它将永远不会到达选项2.)

解决方法

当你调用super.onDestroy()时会发生这种情况.

Android Source

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();
        }
    }
}

从本质上讲,这意味着如果您在代码之前或之后调用它并不重要.

原文链接:https://www.f2er.com/android/313830.html

猜你在找的Android相关文章