在覆盖活动的ondestroy时,我应该在super.onDestroy()之前或之后放置命令吗?
protected void onDestroy() { //option 1: callback before or ... super.onDestroy(); //option 2: callback after super.onDestroy(); }
(现在我担心:如果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(); } } }