Reputation: 7082
In an Android application, I notice that the package name of a class does not have to match the name that was generated when I created the new project. In other areas, Java is insistent that everything matches. I would like to understand why this is not the case for package names, and what the implications are.
Example: I create a new project named TextToSpeech, using my own reverse domain name. This gives a package name of com.lexogram.texttospeech
; the path to the MainActivity.java class file is TextToSpeech/app/src/man/java/com.lexogram.texttospeech/
.
I now go to a TextToSpeech tutorial and copy-and-paste the code into my project. This code uses com.example.texttospeech
as the package name, both in the MainActivity class and in the AndroidManifest.xml. I run the project, and everything works fine.
Does this mean that each activity can use a different package name, so long as the name is used consistently across all files in the activity?
Upvotes: 0
Views: 94
Reputation: 44118
What it means is that your project can have multiple packages inside of it.
Java documentation explains them nicely:
To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups of related types into packages.
Upvotes: 1