Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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>

Yes you can.

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

But your Java code can be organized as you please.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top