2
I created an Activity of type Drawer Navigation and in the icons of this Activity has an action that takes me to a fragment.
My problem is that I don’t know how to come back from a fragment to an Activity ... how should I get back with the back button from onBackPressed?
I tried to simulate the back button with this but it didn’t work here:
Start fragment:
public void showMyFragment(View V){
Fragment fragment = null;
fragment = new MyFragment();
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment)
.addToBackStack(null)
.commit();
}
}
@Override
public void onBackPressed() {
if (getFragmentManager().getBackStackEntryCount() == 0) {
this.finish();
} else {
getFragmentManager().popBackStack();
}
}
public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.activity_info, null);
return v;
}
}
I got it!!! Beautiful! Show!
– Aline