开发者

Android separate code into packages

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 开发者_Go百科Xcode?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜