본문 바로가기

IT/안드로이드 관련

[안드로이드] navigation back button handling

728x90
SMALL

안녕하세요 남갯입니다.

https://stackoverflow.com/questions/51043428/handling-back-button-in-android-navigation-component



Newest Update - April 25th, 2019



public class MyFragment extends Fragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // This callback will only be called when MyFragment is at least Started.
        OnBackPressedCallback callback = new OnBackPressedCallback(true /* enabled by default */) {
            @Override
            public void handleOnBackPressed() {
                // Handle the back button event
            }
        });
        requireActivity().getOnBackPressedDispatcher().addCallback(this, callback);

        // The callback can be enabled or disabled here or in handleOnBackPressed()
    }
    ...
}


728x90
LIST