美文网首页
Android悬浮窗只能接收到ACTION_CANCEL事件

Android悬浮窗只能接收到ACTION_CANCEL事件

作者: 拉赫曼 | 来源:发表于2016-11-07 15:22 被阅读0次

在实现悬浮窗拖动的功能时,偶然遇到当activity最小化时,在onTouch事件里,只能接收到ACTION_CANCEL事件。
原因是使用了错误的Context来初始化WindowManager,用了activity.getSystemService(Context.WINDOW_SERVICE)
而使用 getApplicationContext().getSystemService(Context.WINDOW_SERVICE)之后,onTouch事件工作恢复正常

相关文章

网友评论

      本文标题:Android悬浮窗只能接收到ACTION_CANCEL事件

      本文链接:https://www.haomeiwen.com/subject/jpsouttx.html