How to clear navigation Stack after navigating to another fragment in Android

I am using The new Navigation Architecture Component in android and I am stuck in clearing the navigation stack after moving to a new fragment. Example: I am in the loginFragment and I want this fragment to be cleared from the stack when I navigate to the home fragment so that the user will not … Read more

Receive result from DialogFragment

I am using DialogFragments for a number of things: choosing item from list, entering text. What is the best way to return a value (i.e. a string or an item from a list) back to the calling activity/fragment? Currently I am making the calling activity implement DismissListener and giving the DialogFragment a reference to the … Read more

Programmatically go back to the previous fragment in the backstack

Say I have an activity that has fragments added programmatically: private void animateToFragment(Fragment newFragment, String tag) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.fragment_container, newFragment, tag); ft.addToBackStack(null); ft.commit(); } What is the best way to return to the previous fragment that was visible? I found Trigger back-button functionality on button click in Android but I’m thinking simulating … Read more

How to use data-binding with Fragment

I’m trying to follow data-binding example from official google doc https://developer.android.com/tools/data-binding/guide.html except that I’m trying to apply data-biding to a fragment, not an activity. the error I’m currently getting when compiling is Error:(37, 27) No resource type specified (at ‘text’ with value ‘@{marsdata.martianSols}. onCreate for fragment looks like this: @Override public void onCreate(@Nullable Bundle savedInstanceState) … Read more

How do I add a Fragment to an Activity with a programmatically created content view

I want to add a Fragment to an Activity that implements its layout programmatically. I looked over the Fragment documentation but there aren’t many examples describing what I need. Here is the type of code I tried to write: public class DebugExampleTwo extends Activity { private ExampleTwoFragment mFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); … Read more