android中dialog的dismiss()和cancel()的区别
2016-03-11 12:21
429 查看
dismiss() 主要作用是让dialog从屏幕上消失 源码如下:
cancel() 源码如下:
从源码可以看出2个方法的效果一样都是让dialog消失, 只是cancel() 多了一个DialogInterface.OnCancelListener的回调。
/** * Dismiss this dialog, removing it from the screen. This method can be * invoked safely from any thread. Note that you should not override this * method to do cleanup when the dialog is dismissed, instead implement * that in {@link #onStop}. */ @Override public void dismiss() { if (Looper.myLooper() == mHandler.getLooper()) { dismissDialog(); } else { mHandler.post(mDismissAction); } }
cancel() 源码如下:
/** * Cancel the dialog. This is essentially the same as calling {@link #dismiss()}, but it will * also call your {@link DialogInterface.OnCancelListener} (if registered). */ public void cancel() { if (!mCanceled && mCancelMessage != null) { mCanceled = true; // Obtain a new message so this dialog can be re-used Message.obtain(mCancelMessage).sendToTarget(); } dismiss(); }
从源码可以看出2个方法的效果一样都是让dialog消失, 只是cancel() 多了一个DialogInterface.OnCancelListener的回调。
相关文章推荐
- android线程消息传递机制——Looper,Handler,Message
- android音乐播放器开发 SweetMusicPlayer 实现思路
- Android Voip再次总结 关于数据流的加密和解密
- Android的消息机制
- GitHub 上排名前 100 的 Android 开源库介绍
- Android三种常用动画分享(1)--帧动画
- Android Studio中新建项目提示classes couldn't be instantiated解决方法
- android 测试
- IPC机制---04 Android中的IPC通讯方式(D)
- 设计模式_策略模式
- Android之MVC设计模式
- Android Color Generator
- 史上最详细的Android Studio系列教程(转载)
- Android 使用SVN
- Android 弹无虚发之第四弹:你应该掌握的Notification(Notification的通知栏常驻、Notification的各种样式、Notification点击无效)
- Android Library项目导出aar
- Makefile 中:= ?= += =的区别
- 适配 Android N 需要注意什么
- Android listview设置多个不同的item样式
- Android解惑 - 为什么要用Fragment.setArguments(Bundle bundle)来传递参数