I am trying to refresh a fragment with the code given in this answer:
// Reload current fragment
Fragment frg = null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
However, I don't know what is the tag of my fragment, which is a Navigation Drawer Fragment.
As "Your_Fragment_Tag" I have tried to use the id of content_main.xml, "nav_host_fragment_content_main":
<fragment
android:id="@+id/nav_host_fragment_content_main"
android:name="androidx.navigation.fragment.NavHostFragment"
.... />
And the id of the fragment in mobile_navigation.xml, "nav_settings":
<fragment
android:id="@+id/nav_settings"
android:name="com.geology_quiz_and_guide.mineralogy.ui.settings.SettingsFragment"
android:label="@string/menu_settings"
tools:layout="@layout/fragment_settings" />
Both produce null object reference error in the line of the detach ft.detach(frg);
How can I access to my fragment dynamically on my Navigation Drawer Project?