It is normal that your code does not work. In the first snippet, all you do is create a new instance of PersonalDataFragment , and you will pass it a Bundle with the data. The problem is that although the fragment contains data in the Bundle , the fragment itself is not the one used by the application (it is not even attached to the Activity ). You also install a Bundle on an instance of PersonalDataFragment , but you are trying to access data in WorkExpRefFragment , which obviously will not work, since the two fragments do not have a direct connection.
A simple solution for what you want to do is let the Activity "save" the data for your fragments, since the Activity is available for all fragments. First, create two methods in the Activity containing three fragments:
public void saveData(int id, Bundle data) {
Then your fragments will save their data as follows:
public class PersonalDataFragment extends SherlockListFragment {
To retrieve data in a WorkExpRefFragment fragment:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); YourActivity activity = (YourActivity) getActivity(); Bundle savedData = activity.getSavedData(); }
Depending on how you used these fragments, this solution may not work. Also, keep in mind that the Bundle you submit as described above will not be saved for configuration changes.
source share