To prevent this, follow these steps:
1... Open your graphics control panel NVIDIA? or AMD?
2... Set preferred gpu. In the control panel, navigate to where you can set the preferred gpu for specific applications or games. Look for the option like "Manage 3D settings" in NVIDIA Control Panel or "Switchable Graphics" in AMD Radeon Settings.
3... Save changes and restart your system.