1
votes

I wrote a custom static method to create my fragment. Fragment is a subclass of android.support.v4.app.Fragment class.

Method to create my fragment is bellow.

public static AddItemFragment newInstance(UUID listId, UUID itemId){

        AddItemFragment fragment=new AddItemFragment();
        Bundle bundle=new Bundle();
        bundle.putSerializable(EXTRA_DATA_LIST_ID,listId);
        bundle.putSerializable(EXTRA_DATA_ITEM_ID, itemId);
        fragment.setArguments(bundle);
        return fragment;
 }

In my onCreate method, I am attempting to read data from bundle.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mListId = (getArguments().getSerializable(EXTRA_DATA_LIST_ID) == null ? null : (UUID) getArguments().getSerializable(EXTRA_DATA_LIST_ID));
    mItemId = (getArguments().getSerializable(EXTRA_DATA_ITEM_ID) == null ? null : (UUID) getArguments().getSerializable(EXTRA_DATA_ITEM_ID));
}    

Well the problem is that getArguments() method never returns bundle. It always returns NULL. I don't understand why. savedInstanceState is NULL as well.

1
Inside your onCreate method, try calling getIntent().getExtras() instead of getArguments.Christian Abella
@svager can you show the code that how you instantiate this fragment?adsion

1 Answers

0
votes

Silly me was overriding bundle set in the Fragment with Activity's savedInstanceState bundle which at that point is NULL.

DUH...