I use second monitor on my macbook. When I open some app in fullscreen, and then close the lid, the OS X exit fullscreen mode on plugged monitor and move all windows to it. How to prevent this behavior?
Disable extended desktop
By default the system will attempt to use both the external monitor and internal display in a dual-display setup; however, you can force the system to only use one display with a custom boot argument PRAM setting . To do this, open the Terminal utility and run the following command:
Following this command, restart the system and your system will now either use the internal display, or only use an attached external display. To revert this setting, you can either reset the PRAM or run the following command to clear this value from the boot arguments (reboot for the change to take effect):