'Duplicate Classes to handle app flow (with explicit intents)

I have three different options in my app that allow the user through several of the same classes but at different times, ie

1) Sharing with friend:

MainClass -> InviteFriendOrGroup -> Sharing -> IM

2) Creating event with friends

MainClass -> InviteFriendOrGroup -> CreateEvent -> OpenEventsPage

3) Creating event with no friends:

MainClass -> CreateEvent -> OpenEventsPage

My issue is with the intents to allow for this navigation without so many duplicate classes. For example, in the InviteFriendOrGroup class, onListItemClick method

    Intent i = new Intent(getActivity(), SpecialSharing.class);
    startActivity(i);

which means that only open 1) above is allowed. An easy solution is to make duplicate classes, but with the different intents in them, ie.InviteFriendOrGroupEvent, or InviteFriendOrGroupSharing....

But there has to be a better way?



Solution 1:[1]

You shouldn't duplicate the classes. Pass parameters using "extras" in the Intent to control which options are available.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Wasser