Reputation: 496
I have one splash fragment which is added at main_activity.
I want to do some loading checks for my app, then if everything goes right, I would like to add the navigation drawer fragment and continue to my app.
Otherwise I want to show quit fragment.
What is the best practice or solution to do that? What is the best practice to add and close or quit a fragment? What is the solution for quit fragment?
Background:
I am paused at this for 4 days and can't clean my mess up. If anyone is interested I can give the code here, but it will be a mess and no one is interested to see that, including me.
Thanks again.
Upvotes: 0
Views: 102
Reputation: 360
To remove a Fragment, you can use:
FragmentToBeRemoved fragToBeRemoved = new FragmentToBeRemoved();
FragmentTransaction ft = (FragmentTransaction)getSupportFragmentManager().beginTransaction();
ft.remove(fragToBeRemoved);
ft.commit();
Then remove the Activity by calling:
finish();
Open for correction, as Always! Regards, Edward Quixote.
Upvotes: 1
Reputation: 1155
As fragments are part of an Activity they are not closed but replaced with another fragments. You should use getFragmentManager()
for that. Or if you don't need activity that holding a fragment you can use finish()
method to close activity.
Upvotes: 1