I have a single instance of a custom class, 'encounter' declared in a Fragment, as seen below:
public class EncounterStrategyFragment extends Fragment
implements DialogConfirm.NoticeDialogListener{
private MalifauxEncounter encounter;
This object contains a single List. It is supplied to a custom List adapter which is working as expected. The ListView the adapter is attached to has been registered for a Context Menu, via registerForContextMenu(listview);
.
My problem is that 'encounter's address/id is changing inside the OnContextItemSelected callback method. Here is 'encounter's state everywhere else in the Fragment: (id=830047711760, array size = 10)
But inside OnContextItemSelected it becomes this: (id=830055767320, internal array size = 0)
I'd post pictures, but my reputation isn't high enough...
Outside of OnContextItemSelected the address is the same as it initially was, so the 'encounter Object is not being re-created; it's only different for this single method. So any modifications I try to perform inside OnContextItemSelected cause an error.
My implementation was working properly before I made this fragment part of an ActionBar tab structure.
What the heck is going on?
EDIT: Resolution: The root cause of my issue was that the Fragment was being created twice by the Action Bar tab manager code. The OnContextItemSelected was using the 'encounter' variable from the 2nd instance of the Fragment, whereas the other source was using the copy from the first instance. Resolved using this post: Fragment onCreateView and onActivityCreated called twice