views:

71

answers:

2

I'm just getting into my first android application and just wondering what the convention is here?

Is it more organised to separate my code into various packages? For example.

com.myfirstapp.activity;
com.myfirstapp.database;

I was thinking of doing this as a way of organising my code with database helper files for example kept it .database package.

I have just noticed that data is stored in /data/data/YOUR_PACKAGE/ does this mean that when on a device I would end up having data stored all over the place if I use different packages?

If this is not right what is a better way of organising code in Eclipse much like you do in Xcode?

+1  A: 

Yes, please separate your code into packages. That's a beautiful concept of Java.
The file name your app is stored under is determined by manifest package element (which will be com.myfirstapp in your case).
Also have a look at Declaring class names section.

alex
For the manifest package element to be unique and ideally end up in the marketplace how deep does it have to be? eg. com.appname, or com.company.appname, or com.company.project.appname, etc?From that link that does that mean my Android Manifest package element should be as follows:<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.appname"assuming that my packages under it are com.appname.activity, and com.appname.database?I was originally under the impression that the manifest was just for the one package, but its actually for the whole application?
Daniel Bowden
Yes, AndroidManifest.xml is for the entire app. You need to grasp the basics of Java and then read about Android. Esp. if coming from iPhone development.
alex
A: 

All your source file are stored int the src folder of your project. In the apk that is generated all your classes seem to be merged to a classes.dex file.

Keep your classes in the res folder and organize them into as many packages as you think you need. I normally have a data package that contains my data classes, packages like sound, database, location... that contain classes/controller for this various topics and then I have a ui package that holds several sub packages for the main branches in my User Interface.

Janusz