Weird action when changing the way to get Intent value


In CrimeFragment, this command is used to get the id in Intent: UUID Id = (UUID)getArguments().getSerializable(EXTRA_CRIME_ID); Using this command lead to the problem of not displaying the right CrimeID and it’s fixed by using setCurrentItem.
I try to change the way to get the ID from Intent by using the command: UUID Id = (UUID)GetActivity().getIntent().getSerializableExtra(EXTRA_CRIME_ID); then the ViewPager display the right CrimeID. However, when I swipe to change Crime, it does not work.
Can u explain to me what the problem is?


If you use this code:

UUID id = (UUID)getActivity().getIntent().getSerializableExtra(EXTRA_CRIME_ID);

…then CrimeFragment will always display the crime associated with the activity that owns the fragment, not the crime the fragment was configured to display.

Your first solution is correct - call setCurrentItem to display the fragment which shows the crime associated with the activity.