I will not talk about the 'why', just about the 'how' :-)
So, about
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
This will not affect tablet devices, which use a system bar rather than a separate navigation
and status bars.
On Tablet, you could try (API Level 14 onward)
myView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
To detect the event, I think you could use this to catch the event:
myView.setOnSystemUiVisibilityChangeListener(
new OnSystemUiVisibilityChangeListener()
{
public void onSystemUiVisibilityChange(int visibility)
{
if (visibility == View.SYSTEM_UI_FLAG_VISIBLE) {
// TODO whatever you want
}
else {
// TODO what to do in the other case
}
}
}
);
More generally, here is an additional advice from 'Professional Android 4 Application development'
It’s generally good practice to synchronize other changes within your
UI with changes in navigation visibility. For example, you may choose
to hide and display the Action Bar and other navigational controls
based on entering and exiting “full screen mode.” You can do this by
registering an OnSystemUiVisibilityChangeListener to your View —
generally, the View you are using to control the navigation visibility
.