在覆盖活动的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(); } } }
原文地址:https://www.jb51.cc/android/313830.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。