Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize Android source code into folders

Tags:

java

android

I'm working on an Android app and it's up to 17 classes. I want to start organizing the .java class files into a more intuitive layout.

Say I want to have a source code directory called "views". When I create that directory using Eclipse, it changes my package name to com.xyz to com.xyz.views.

Since this package name (com.xyz.views) is different than the rest of my app (com.xyz) is this going to cause me to do a lot of extra work to link those packages? Will this cause problems with the fact that Android Market looks at the package name and is more or less locked to the package name?

like image 393
Brad Hein Avatar asked Feb 04 '23 03:02

Brad Hein


2 Answers

I'm organizing my app src in different subfolders. There's no problem with it.

is this going to cause me to do a lot of extra work to link those packages

Isn't that what a smart IDE would do when you refactor the classes via the 'refactor' context menu? At least Eclipse and IntelliJ should do that.

In my manifest, I have

<manifest package="com.myapp.android"

while my activities for example (in your case would be 'views') are referenced as:

<activity android:name=".activity.main.Splash"

Works fine for me.

So, part of my folder structure is for example

com/myapp/android/
com/myapp/android/activity
com/myapp/android/util
com/myapp/android/model
like image 167
Mathias Conradt Avatar answered Feb 05 '23 15:02

Mathias Conradt


Java works like that, it uses separate files for separate public classes and folders for packages. If you want a source folder, you will also get a corresponding Java package. A smart IDE should take care of the imports and references for you.

Subpackages should be handled by Android just fine, don't worry about that.

like image 43
Gintautas Miliauskas Avatar answered Feb 05 '23 15:02

Gintautas Miliauskas