If you develop apps for Android you may have noticed, that you quickly lose the overview of your layouts, ids, drawables, packages, etc. I want to share my experience with you and suggest a few tips, how to organize your projects. I consider myself to these rules, because they help me (and of course others) a lot to know about the project. If you work as a team it is even more important to define rules for the naming and the organization of the project.
- The res folder
- Separating paid & free version
The res folderI'm always trying to write as much as possible in XML and not in Java, so the resources folder can contain a lot of files. There are layouts, menus, strings, etc. If you have a lot of layouts you'll have a lot more ids.
Naming of layouts
Naming of IdsI advise you to give only those widgets an id, that you'll need in your code. So mostly you can remove the id-attribute of layouts and scrollviews. To keep the overview over your ids, I suggest to put the layout name and the widget name in front of the id name. <layout>_<widget>_name
- activity_dashboard_btn_profile or a_dashboard_btn_profile
- Button = btn
- ImageButton = ibtn
- EditText = et
- TextView = tv
- ImageView = iv
Separation in the values folderI really³ advise you to use styles and themes. It's a simple way to give your app a unique look. In my last project i end up with the following files. The biggest advantage is, that you can define different values for different screen sizes, languages, etc. .
Naming of drawablesThis is similar to layouts and ids.
PackagingThis chapter is also very important. I think most of you know how to use and name packages useful, but I've seen a lot of projects were all classes are stuffed in one packet. So here are some suggestions For the main package take your website's url and reverse it or your company name: <country code>.<company name>.<project name> Examples:
- adapter (list adapters)
- map (map overlays)
- sql (SQLite stuff)
- util (General classes like Helpers, etc.)
Separating paid & free versionYou want to sell an app in the Android Market, but also want to provide a free demo. It would be annoying if you always have to edit the code in to projects. The solution to that is called "Library project". Create a new project and extend the package name with ".library". Add "public static boolean isFreeVersion=true;" to your main activity and develop your app as usual. Use this boolean if you want to block something in the free version. If you're done create 2 new projects one for the full and one for the free version. The package names could look like this:
- Lib: at.bartinger.smartphone.library
- Full: at.bartinger.smartphone
- Free at.bartinger.smartphone.free