1

I am writing an Android app which uses immersive mode quite extensively (a kiosk application to be precise). I however am noticing that every time it switches between activities the navigation bar pops into view for a short instant (not long enough to be useful for a normal user, but just long enough for curious users to push the home button and easily quit the Kiosk application).

Example of how I am setting my system visibility flags:

@Override
public boolean onTouchEvent(MotionEvent event) {
    setImmersiveMode();
    return super.onTouchEvent(event);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setImmersiveMode();
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    setImmersiveMode();
    return super.dispatchTouchEvent(ev);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        setImmersiveMode();
    }
}

protected void setImmersiveMode() {
    getWindow().getDecorView()
            .setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                            | View.INVISIBLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

and I start my activity like so:

Intent intent = new Intent(MyParentActivity.this, MyNextActivity.class);
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("my_var", "some useful stuff");
intent.putExtra(EXTRA_MESSAGE, hashMap);
startActivity(intent);

During the time in which the current activity goes blank and the next activity starts loading the navigation buttons and action bar appear. Once the next activity loads it calls the setImmersiveMode() method and effectively sets things back to the desired visibility states. I can not determine a way to switch activities without these Android UI elements blinking into existence.

Has anyone ever run up against this issue before with any resolve?

Notes:

  • The devices I use only have "soft buttons".
  • I am running my app on an Android 4.4.2 device.
  • I have done some searching on the net but was unable to find anything sufficient to resolving this.
  • I am relatively new to Android programming.

And thanks for any assistance.

Logic1
  • 1,806
  • 3
  • 26
  • 43
  • https://developer.android.com/training/system-ui/immersive.html – ecle Jul 03 '15 at 07:55
  • I have read that document before and I did not see any mention of ways to manage this behavior. Thank you though. – Logic1 Jul 03 '15 at 08:15
  • 1
    How about the example? https://developer.android.com/samples/BasicImmersiveMode/src/com.example.android.basicimmersivemode/BasicImmersiveModeFragment.html – ecle Jul 03 '15 at 08:20
  • http://stackoverflow.com/questions/19750700/detecting-when-system-buttons-are-visible-while-using-immersive-mode – ecle Jul 03 '15 at 08:21
  • Very interesting, hadn't thought of using fragments (still learning..). I'll definitely be giving that example a look though! Thanks. – Logic1 Jul 03 '15 at 09:32

2 Answers2

2

I had the same problem for the past two day and found out my solution here:

https://stackoverflow.com/a/37098583/4122679

MyActivity.java

@Override
protected void onResume()
{
   hideAndroidApplicationBar();
}

private void hideAndroidApplicationBar()
{
     final View view = getWindow().getDecorView();
     // Hide Android Soft keys
     view.setSystemUiVisibility(
           View.SYSTEM_UI_FLAG_LAYOUT_STABLE
           | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
           | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
           | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide navigation bar
           | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
           | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

Styles.xml (\res\values\styles.xml)

<style name="noTitleBarAndAnimation" parent="android:Theme.NoTitleBar.Fullscreen">
         <item name="android:windowAnimationStyle">@null</item>
         <item name="android:windowTranslucentNavigation">true</item>
         <item name="android:windowDisablePreview">true</item>
</style>

The magic comes from the "android:windowDisablePreview"

Now, there my navigation act as normal!

Community
  • 1
  • 1
  • Please don't give link-only answers. You should consider adding the relevant solution to your answer. Otherwise it's hard to get what exactly solved the problem and it's always possible that the link went down. Give credit where credit is due. – morten.c Mar 01 '17 at 17:50
  • 1
    Edited my answer. – Maxime Limoges Mar 02 '17 at 14:09
1

Calling setImmersiveMode() in the onCreate() method of the next activity should prevent the status bar and the navigation bars from appearing briefly during switching.

Icarus
  • 228
  • 1
  • 10