title: Android Destination Fragment not Appearing on Navigation
body: <p>I'm trying to use a navigation graph to navigate between two fragments. For some reason, when I call the navigate method with the graph's generated action, the destination fragment is being &quot;created&quot; but not appearing, while the start fragment just sits as if it's been inactivated but doesn't go away. I think I've followed all the steps listed on <a href="https://developer.android.com/guide/navigation/navigation-getting-started" rel="nofollow noreferrer">Google's documentation page for this</a>, but I am probably missing something simple!</p>
  <h1>Here are my dependencies:</h1>
  <pre><code>dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'androidx.appcompat:appcompat:1.1.0'
      implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
      // ViewModel and LiveData
      def lifecycle_version = &quot;2.1.0&quot;
      implementation &quot;androidx.lifecycle:lifecycle-extensions:$lifecycle_version&quot;
  
      def nav_version = &quot;2.1.0&quot;
      implementation &quot;androidx.navigation:navigation-fragment:$nav_version&quot;
      implementation &quot;androidx.navigation:navigation-ui:$nav_version&quot;
  
      implementation 'androidx.legacy:legacy-support-v4:1.0.0'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'androidx.test:runner:1.2.0'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  }
  </code></pre>
  <h1>MainActivity</h1>
  <p>In my main activity class, I'm just defining a <code>ModelView</code> in <code>OnCreate()</code>:</p>
  <pre class="lang-java prettyprint-override"><code>public class MainActivity extends AppCompatActivity {
      MealDataModel mealDataModel;
     
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // Create the model on create of the main activity
          mealDataModel = ViewModelProviders.of(this).get(MealDataModel.class);
      }
  }
  </code></pre>
  <p>And in my main activity layout, I'm just using the NavHostFragment:</p>
  <pre><code>...
  &lt;fragment
          android:id=&quot;@+id/fragment2&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          app:defaultNavHost=&quot;true&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:navGraph=&quot;@navigation/nav_graph&quot; /&gt;
  ...
  </code></pre>
  <h1>Navigation Graph</h1>
  <p>And here is my navigation graph:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;navigation xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/nav_graph&quot;
      app:startDestination=&quot;@id/mealCostFrag&quot;&gt;
  
      &lt;fragment
          android:id=&quot;@+id/mealCostFrag&quot;
          android:name=&quot;com.finley.program2.frag.MealCostFrag&quot;
          android:label=&quot;fragment_meal_cost&quot;
          tools:layout=&quot;@layout/fragment_meal_cost&quot; &gt;
          &lt;action
              android:id=&quot;@+id/action_mealCostFrag_to_tipPercentFrag&quot;
              app:destination=&quot;@id/tipPercentFrag&quot; /&gt;
      &lt;/fragment&gt;
      &lt;fragment
          android:id=&quot;@+id/tipPercentFrag&quot;
          android:name=&quot;com.finley.program2.frag.TipPercentFrag&quot;
          android:label=&quot;fragment_tip_percent&quot;
          tools:layout=&quot;@layout/fragment_tip_percent&quot; /&gt;
  &lt;/navigation&gt;
  </code></pre>
  <h1>Start Fragment</h1>
  <p>My start destination of the navigation graph is this fragment...:</p>
  <pre><code>public class MealCostFrag extends Fragment {
      private MealDataModel mealDataModel;
      private EditText etCost;
      private Button btnNext;
      private double cost;
      public MealCostFrag() {
          // Required empty public constructor
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View myView = inflater.inflate(R.layout.fragment_meal_cost, container, false);
          mealDataModel = ViewModelProviders.of(getActivity()).get(MealDataModel.class);
  
          // Set listeners and such...
          etCost = myView.findViewById(R.id.editText01);
          btnNext= myView.findViewById(R.id.button01);
          btnNext.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  try {
                      cost = Double.parseDouble(etCost.getText().toString());
                      if (cost &lt;= 0) throw new Exception();
                      mealDataModel.setMealCost(cost);
                      Log.i(&quot;COST FRAG&quot;,&quot;Navigating to tip pct with cost = &quot; + mealDataModel.getMealCost());
                      Navigation.findNavController(v).navigate(R.id.action_mealCostFrag_to_tipPercentFrag);
                  } catch (Exception e) {
                      Log.e(&quot;COST FRAG&quot;, &quot;Invalid cost entered, cost = &quot; + cost);
                      Toast.makeText(getContext(),
                              &quot;Please enter a valid meal cost.&quot;, Toast.LENGTH_SHORT).show();
                  }
              }
          });
          return myView;
  
      }
  
  }
  </code></pre>
  <p>With this layout:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.frag.MealCostFrag&quot;&gt;
  
      &lt;EditText
          android:id=&quot;@+id/editText01&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;55dp&quot;
          android:layout_marginStart=&quot;64dp&quot;
          android:layout_marginLeft=&quot;64dp&quot;
          android:layout_marginTop=&quot;48dp&quot;
          android:layout_marginEnd=&quot;16dp&quot;
          android:layout_marginRight=&quot;16dp&quot;
          android:ems=&quot;10&quot;
          android:gravity=&quot;center_horizontal|center_vertical&quot;
          android:hint=&quot;Cost&quot;
          android:inputType=&quot;number|numberDecimal&quot;
          android:textSize=&quot;24sp&quot;
          app:layout_constraintEnd_toStartOf=&quot;@+id/button01&quot;
          app:layout_constraintHorizontal_bias=&quot;1.0&quot;/&gt;
  
      &lt;Button
          android:id=&quot;@+id/button01&quot;
          android:layout_width=&quot;87dp&quot;
          android:layout_height=&quot;46dp&quot;
          android:layout_marginEnd=&quot;64dp&quot;
          android:layout_marginRight=&quot;64dp&quot;
          android:text=&quot;Next&quot;
          app:layout_constraintBaseline_toBaselineOf=&quot;@+id/editText01&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <h1>Destination fragment:</h1>
  <p>Here's the fragment I'm trying to navigate to is this, with an empty layout:</p>
  <pre><code>public class TipPercentFrag extends Fragment {
      private MealDataModel mealDataModel;
      public TipPercentFrag() {
          // Required empty public constructor
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View myView = inflater.inflate(R.layout.fragment_meal_cost, container, false);
          mealDataModel = ViewModelProviders.of(getActivity()).get(MealDataModel.class);
  
          // Set listeners and such...
          Log.i(&quot;TIP PCT FRAG&quot;, &quot;CreateView of tip pct frag called&quot;);
  
          return myView;
  
      }
  }
  </code></pre>
  <p>What I find peculiar about this is the logs from inside the destination fragment's 'onCreateView()' method are being output, but it is just not displaying.</p>
  <p>I know I've provided a massive wall of code for all of you to sift through, so I will be extra appreciative to anybody willing to spend some time helping me out. I will provide any extra necessary info upon request. Thank you all in advance, and hopefully it's a comically trivial error I'm making!</p>