Fragment addToBackStack() and popBackStackImmediate() not working

前端 未结 6 2028
清酒与你
清酒与你 2020-12-08 20:00

I am currently building an application for Android (14 <= SDK <= 21) by using one ActionBarActivity and more Fragments, such as ListFra

6条回答
  •  清歌不尽
    2020-12-08 20:30

    First of all, I wanted to say a big thank you to the highlighted [Nick]'s answer (Low reputation can't comment underneath), for helping me know there WAS actually something that didn't get mentioned in the Android Documentations.

    Second, it's 2019 now, and after stumbling for a similar way in Androidx's Preferences, I couldn't find anything for a long time, until I was both checking this question and an official sample code in Kotlin, which this question led to a clue and the sample code's way actually was the solution in my case, works like a charm with a very tiny piece of overwriting, hope it helps as well for those who are looking for an official solution

    @Override
    public boolean onSupportNavigateUp() {
    
        if (getSupportFragmentManager().popBackStackImmediate()){
            return true;
        }
    
        return super.onSupportNavigateUp();
    }
    

    Aforementioned code in Java (Screenshot)

    P.S. My first answer EVER on stacksoverflow, after more than of at least 5 years of using it ^^

提交回复
热议问题