Hi Ashish, this problem occurs because the fragment can not understand how normal activity is in normal activity when you press a key while the recently used activity will automatically open, but in the fragment it will not happen when you press the back button , so we must support the opposite event in the fragment, here I use the code from which I process the activity of my fragment, so you can check this
public void onListItemClick(ListView l, View v, int position, long id) { showDetail(position); } void showDetail(int position) { this.position=position; if(isDualPane){ getListView().setItemChecked(position, true); DetailFragment detailFragment = (DetailFragment) getFragmentManager().findFragmentById(R.id.detail); if (detailFragment == null || detailFragment.getIndex() != position ) { detailFragment = new DetailFragment(position); FragmentTransaction ft =getFragmentManager().beginTransaction(); ft.replace(R.id.detail, detailFragment); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); } } else { Intent intent =new Intent(); intent.setClass(getActivity(),DetailActivity.class); intent.putExtra("position", position); startActivity(intent); }
see the else part shows that intent supports my snippets
please check out my example (Fragment With Gridview), which I have for all users of fragments, you will find something useful from it
check my answer at this link: How to show various layouts inside fragments
source share