I am creating a common place/class for all the action that can happen when a user clicks on AlertDialog option. I found this link but its not really helping me understand the concept. This is what I am looking to do.
- I have a class (ClassA) which extends from Activity and another class(ClassB) which extends from ListActivity.
- I have the alert dialog popping up regardless from where it is called.
- I have created a BaseRootActivity class which is extended in ClassA. Since ClassB extends from RootListActivity class, I am not able to invoke methods sitting inside the BaseRootActivity especially the ones which uses the context methods.
I can , based on the link, create two separate generic list Activities but the code would get duplicated in both the classes. I would like to avoid that. Is there a way I could do that, I understand the answer might be in the link given however, I am not really able to comprehend the underlying logic the user is stating. I would appreciate any help on this.
You should always prefer composition over inheritance. So, you have two good choices:
ClassAandClassB(not extending it, just using it).DialogFragmentthat basically forces you to create dialogs on separated classes (which is a great idea, by the way), and that will help you handle the problems you could face if you choose to follow the first choice.