0

I am busy reading up of fully qualified names and packets etc,

In my project I have broken everything up into packages just to try and organize my project, but I have now realized this doesn't quite fit with the android manifest element as you can only provide one package?

Can I have multiple packages in my project like so?

enter image description here

Robi Kumar Tomar
  • 3,418
  • 3
  • 20
  • 27
Zapnologica
  • 22,170
  • 44
  • 158
  • 253
  • say you can, for that your first name of the package should be the one you used while creating or in menifest. As I had mine as myproject.test and then every new package was onwards like myproject.test.anything – Saqib Apr 23 '14 at 09:59

4 Answers4

3

You should specify a main package, and that package may have as many sub-packages as you like:

com.example.android could be a main package.

then you could specifiy the following:

com.example.android.activities
com.example.android.adapters
etc...

Of course, you may add classes to the 'root package' too without any hassle.

Check out Java package naming conventions for more info, Android follows these conventions as well.

Smokez
  • 382
  • 1
  • 5
  • So if I just put all of my packages under the com.example.appname package it should be correct. Because I understand that some intents need to use the fully qualified name, Does my main package have to be a unique name? what if some one out there has the same package name, and the install both apps? – Zapnologica Apr 23 '14 at 10:04
  • 1
    Of course you don't really use "com.example.appname". Read http://stackoverflow.com/questions/6273892/android-package-name-convention and click the links. We talk about **conventions**, which means that you don't **have** to follow them, but everyone will live happier if we do follow. Also, indeed, if someone decides to use the exact same package name problems could occur. But that's why you use your own domain name etc. to create as much diversity as possible. – Smokez Apr 23 '14 at 10:12
2

You have to Specify a common package name for your application. eg:com.example.rhino68mobileapp and start every other packages by using this eg:com.example.rhino68mobileapp.utils

Asha Soman
  • 1,846
  • 1
  • 18
  • 28
1

Yes you can use the multiple package in android, Only you have to play with access modifiers within your application, so that your one package class or object can communicate with other package class when desired.

Java provide different access modifiers:

  • Visible to the package. the default. No modifiers are needed.
  • Visible to the class only (private).

  • Visible to the world (public).

  • Visible to the package and all subclasses (protected).

For more read here

Edited:

You can define the main package(Application main package) and other package into your manifest like this:

<manifest package="com.example.mainPackage">
  <application . . .>
    <activity android:name=".packageOne.ActivityOne" . . . />
    <activity android:name=".packageTwo.ActivityTwo" . . . />
   <activity android:name=".packageThree.ActivityThree" . . . />
  </application>
</manifest>
Robi Kumar Tomar
  • 3,418
  • 3
  • 20
  • 27
0

Yes you can.

The application package from the AndroidManifest.xml identifies your app.

But your Java code can be organized as you please.

shkschneider
  • 17,833
  • 13
  • 59
  • 112