I need to inherit the functions and the graphic section of an activity in Android Studio, I need to make many more activities with the same format with the difference that I will change the name of the "Activity", however, when inheriting the class two things happen , the methods cannot be used and the graphic part is not shown in the Android Studio editor, what can I do?
PS: The inheritance as such works, but I can't edit it in any way, also the encapsulation is well done.
Good morning @michel. Activity inheritance is not very complicated in Android Studio, and it allows you to avoid code duplication. You can use it in various ways depending on what you are looking for. For example: If you have two different activities and in each one you need to implement a common method (for example an animation), you can inherit these activities to a parent class, which in turn extends activity, then you will declare the method in that activity, must have public or protected access modifier (I suggest you use protected whenever you can to maintain the language's own encapsulation) and finally call the method from anywhere in the two activities. For example: Main.java
Activity1.xml
Activity1.java
Activity2.xml
Activity2.java
Now if what you mean in the question is to implement several activities with the same graphic design, you would not be using inheritance, but rather reusing the same xml design for several activities. For example: if you have several activities with the same graphic design, or with similar graphic designs, you can create a single xml file with the design, and then, when you call the setContentView() method, you pass the xml as an argument. For example:
graphic_design.xml
Activity1.java
Activity2.java
In this way, when launching Activity1 or Activity2, both would have the same graphic design, which you can change as you want. You can also use the two solutions together, as long as they suit your project. I hope I have clarified your doubts regarding the inheritance of activities in Android Studio.