Reputation: 678
I have a fragment which has a context menu which in turn calls another fragment:
switch (item.getItemId())
{
case MENU_EDIT:
FragmentTransaction ft =getActivity().getFragmentManager().beginTransaction();
PlayListDetailsView fragment=new PlayListDetailsView();
//fragment.getArguments().putLong("id", (Long)info.id);
ft.add(android.R.id.content, fragment);
ft.attach(fragment);
ft.commit();
}
The new fragment opens alright, but once i press back the app totally exits withour going back to the fragment it was called from. Also the commented line of an attempt to add a bundle information fails and cannot be retrieved in the fragment called Suggest a fix please :)
Upvotes: 0
Views: 639
Reputation: 5593
First of all fragments should communicate through activity, not directly: http://developer.android.com/training/basics/fragments/communicating.html
As for your question:
For back key to work properly, you should add transaction to back stack, put this before commit:
ft.addToBackStack("playlistdetails");
Arguments should be added like this:
Bundle args = new Bundle();
args.putLong("id", (Long)info.id);
fragment.setArguments(args);
Upvotes: 2