2

I've read up on a lot of questions about immersive sticky mode on Android, but I cannot find a specific answer for my question.

I have read onBackPressed function not working under IMMERSIVE STICKY mode, but my app goes back successfully when an ImageButton is pressed.

I want to remain in immersive sticky mode for the whole duration of the app. There is no problem when I launch a new activity, with and without a shared element transition. However, when I go back, the system bars sometimes appears then soon slide out of view again. This happens especially when I stay on an activity for a while.

This transition is called from _TrickPage.class:

public void setBorroRingsOnClickListener(View view){
    dBHelper.close();
    Intent intent = new Intent(this, _DominoScene.class);
    startActivity(intent);
}

And I call finish() to get back to _TrickPage.class from _Domino.class:

findViewById(R.id.picture).setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
        dBHelper.close();
        finish();
    }
});

Another transition I use is a shared element transition. The following is an inner class of ButtonAdapter, which extends BaseAdapter, an object in my _Submenu Activity:

class MyOnClickListener implements View.OnClickListener {

    private final int position;

    public MyOnClickListener(int position){
        this.position = position;
    }

    @Override
    public void onClick(View v) {
        ...

        //link clicked button to _TrickPage button for shared transition
        v.setTransitionName("trick");

        //make and start shared transition to _TrickPage
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
                (Activity)mContext,
                new Pair<View, String>(v, "trick")
        );
        Intent intent = new Intent(v.getContext(), _TrickPage.class);
        v.getContext().startActivity(intent, options.toBundle());
    }
}

Finally, to get back to _Submenu from _TrickPage, I call finishaftertransition():

    picture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dBHelper.close();
            hideMainContent();
            finishAfterTransition();
        }
    });

I set the UI flags in the onCreate() and onResume() methods of the Activities involved: _Submenu, _TrickPage, and _DominoScene. I also have the following in each activity:

public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    //if (hasFocus)
        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);

    if (hasFocus && playAnimations) {
        //showMainContent();
        playAnimations = false;
    }
}

This is my first time asking a question on Stack Overflow, so please ask for any other parts of my code if you think there could be a problem there. Thanks!

Community
  • 1
  • 1

1 Answers1

0

Call this method on your onCreate method from every Activity(right after your setContentView method). And also on the onWindowsFocusChanged

public void goImmersive()
{
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);
}
  • All the involved activities do have this code executed in OnCreate() (after the setContentView() call), OnResume() and onWindowsFocusChanged(). Though I can go through and refactor by doing this, I don't think it will solve the problem. – DiDoubleTwice Nov 13 '16 at 22:59
  • It didn't work for me. I created a global static method `goImmersive(Window window)` with the method body above so all activities can use it by calling `HelperFunctions.goImmersive(getWindow());` I placed this method call in OnCreate() after setContentView() and in the onWindowsFocusChanged() methods in every activity, but the bars still flash when I go back. – DiDoubleTwice Nov 22 '16 at 19:01