I have an Activity which launches a Fragment called main page. This page has cards with buttons and each button opens a new fragment. The problem is that when it opens a new fragment it seems to start a new Activity, which is not the main one, launched at first. For this reason the toolbar I have on the main Page doesn't appear on other pages which are opened on the click from the Main fragment.
Does anybody knows how to make it not change the first Activity or at least how to access it from other fragments. When I try getActivity()
or getContext()
from these Fragments it is never the same Activity loaded initially.
Btw, the first Activity extends AppCompactActivity
AppActivity activity = (AppActivity) v.getContext();
activity.getSupportFragmentManager().beginTransaction().replace(R.id.drawer_layout, myFragment).addToBackStack("string").commit();
(Appears in the main fragment on click)