I have an activity(Activity1) with several fragments. I'm calling a second activity(Activity2) from one of the fragments(say Fragment C) of first Activity. I want to navigate back from the second activity(Activity2) to Fragment C. But, it is navigating to the first fragment of Activity1 instead of Fragment C. Please help.
Block of code I have tried so far:
In Fragment C,
categoryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(getActivity(),Activity2.class);
getActivity().startActivity(i);
}
});
In the container Activity i.e Activity1,
FragmentTransaction transaction= getSupportFragmentManager().beginTransaction();
FragmentC myFragment = new FragmentC();
transaction.replace(R.id.frame_container, myFragment);
transaction.commit();