0

I have a button in a Bottom Sheet fragment and the app should exit the fragment.

I tried a couple different ways to do it, but none of the ways I tried worked.

  1. I tried to use getActivity.onBackPress(), it worked, but it exit the entire app. I tried to press the back bottom manually, it goes to the main Activity. To exit the app, i need to press the back button twice, however, I only did onBackPress() once in my code, it still exit the app.

  2. I tried to use getActivity().getFragmentManager().popBackStack();, and I found out my backstack is empty (null) when I execute this and the code would not do anything.

pppery
  • 3,731
  • 22
  • 33
  • 46
Time
  • 65
  • 1
  • 5

1 Answers1

0

You can use the dismiss method for this.

Check this out if it helps : Show and Hide Bottom Sheet Programmatically

  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259/165483) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Samuel Liew Jun 04 '20 at 14:24