How to detect when device goes to multi-window mode of Android N

谁都会走 提交于 2019-12-10 14:34:28

问题


I want to get notified from my background service when the user switches to multi-window mode. Is there a way to get this information by a service other than the activities involved in the process.

Also I have noticed that when an overlay is clicked on the area of the foreground window it automatically switches to the activity under the area. Can this be prevented?


回答1:


You must add ViewTreeObserver. And check if device enter in Multi-Window mode getActivity().isInMultiWindowMode()




回答2:


isInMultiWindowMode() is added in API 24 to check device is in Multi window or not, it returns a boolean value. when ever device goes to Multi window it triggers onConfigurationChanged() method. There you can handle Landscape and portrait mode.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
     if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
      {
        //do something
      }else{

      }
}


来源:https://stackoverflow.com/questions/42718275/how-to-detect-when-device-goes-to-multi-window-mode-of-android-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!