Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am starting a new Android application. What is the best structure to use?

I am planning to make it a multi-package design as follows:

  1. Main package, including the Activity
  2. Service and data layer
  3. Entity package, including entity class.

    Any advice ?

share|improve this question

2 Answers

up vote 7 down vote accepted

First, it depends on what application you are doing.

you should do a textual or schematic description on how a user will work with application. Fix down every possible scenario. Put down examples that will be used later for tests.

Decide what belongs to the functionality and what - to the changeable configuration. Extract functionalities and data entities from scenarios.

From scenarios make decision what your app will be. Is it service, activity, widget , even a content provider or a complex system, including some different components. Test your decision against scenarios.

In the case of the complex system, distribute functionalities and data entities among application components. Make a list of components and what they are (activities or smth else).

Make the list of UI components with description what they do (not HOW yet) These will be widgets and activities or fragments or layouts later.

Make draft layouts for UI components. Make simple passes from one to another. Look at the UI. Return to scenarios and play all of them them with your draft UI. All UI components and classes put into one hierarchy of packages or package.

Make a list of data entities. Decide what will be in what. Plan them as collections or tables in DB or different DBs. Make them as classes, put them into another hierarchy of packages or another package. Here also put DB helpers - classes that talk with DB by SQL.

Make a testing classes/JUNITs for fillling UI and data entities with test data and launching them.

Adapters needn't be public, for they are used in their parent GroupView only. So, no files for adapters usually.

Do not put all globals into special static classes - it is a bad practice. You are mixing so the code and the configuration.

Configuration data put into recources. If some of them are complex, use XML sources and parser(s). Make readers of resource data into global variables. Not all of them will be static! They could belong to the main Activity instance, for example.

Do not use unconfigurable constants in the code! May be, your name only :-). Every constant becomes non-constant sometimes.

Always do so:write something - connect something to a bulk - add test(s) for this new thing - test this new one - test the bulk - repeat. Small steps only!

share|improve this answer

Yes it make easy to develop if you categories thing on base their work.You are in right direction.In android,if develop an application then i will use following structure, something will similar like you

1)Main package With all Screen Activity

2)Adapter classes if i am using ListView, GridView that need BaseAdapter etc

3)Parsing helper if used

4)Database

5)Entity Classes and Classes to store static variable

6)Service and Receiver

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.