A
A
Alexander Vasilenko2016-08-18 12:19:52
Android
Alexander Vasilenko, 2016-08-18 12:19:52

How to exit to the main screen of the device from an application that first destroys the fragment (leaving a void), after pressing the back button?

The point is this. There is MainActivity. It has two fragments: a MapFragment to display a Google map, and my own fragment, let's say the CurrentFragment.
The transaction is done like this (I pass null to the backstack)

private void beginTransactionWithReplacement(Fragment currentFragment, String backStackString){
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.store_container, currentFragment)
                .addToBackStack(backStackString)
                .commit();
    }

When you click on the back button, the CurrentFragment is first destroyed (an empty space remains) and only when you click on the backbutton again, I get to the main screen of the device.
What should I do so that in this situation I can immediately get to the main screen of the device?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-08-18
@SanchelliosProg

Don't make .addToBackStack(backStackString)
the fact that you passed null there means that the transaction name in the backstack is null and the transaction is still in the backstack. Just don't add it there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question