문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top