Android悬浮窗只能接收到ACTION_CANCEL事件
2016-11-07 本文已影响0人
拉赫曼
在实现悬浮窗拖动的功能时,偶然遇到当activity最小化时,在onTouch事件里,只能接收到ACTION_CANCEL事件。
原因是使用了错误的Context来初始化WindowManager,用了activity.getSystemService(Context.WINDOW_SERVICE)
而使用 getApplicationContext().getSystemService(Context.WINDOW_SERVICE)之后,onTouch事件工作恢复正常