I know of 2 ways wich both have their (dis-)advanteges.
1) You can detect if your app is going to the background which happens when the user opens the menu. The handler is:
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
There you can close ALL system menus, even the menu to reboot or turn off the device!
This is done with this intent:
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
2) You can start a run a service with a background worker that is checking the front app very often (like twice a second). You can get the foreground app like this:
String packageName;
String className;
ActivityManager amen = (ActivityManager)getBaseContext().getSystemService(Activity.ACTIVITY_SERVICE);
packageName = amen.getRunningTasks(1).get(0).topActivity.getPackageName();
className = amen.getRunningTasks(1).get(0).topActivity.getClassName();
The package name for the settings is: com.android.settings
If you detect it you can simply start an intent that brings your app back to the foreground.
Hope it helps :)