Search code examples
javaandroidclassdirectory-structure

How should java classes be organized?


I am new to Java and to Android development. In all the tutorials at my current level of understanding, the only user-created classes are found in the directory app/src/main/java/com.example.project/, and all these classes refer to views.

In my project, I will need to write a number of classes which are not directly related to any particular views. For example, a TextToSpeech class and a PatternRecognition class.

What are considered to be the best practices for managing the class files in the directory hierarchy? What online resources can you recommend, so that I can explore this question in more detail?


Solution

  • I'm not sure, that this is the best way, but my Android projects looks like this:

    src
    ├───androidTest
    │   └───java
    │       └───hu
    │           └───company
    │               └───app
    │                   └───activities
    │                       ├───login
    │                       └───main
    └───main
        ├───assets
        │   └...
        ├───java
        │   └───hu
        │       └───company
        │           └───app
        │               ├───activities
        │               │   ├───login
        │               │   ├───main
        │               │   ├───mainMenu
        │               │   └───surveys
        │               ├───common
        │               └───communication
        └───res
            └──...
    

    And in the hu.company.app package, I have more packages. All of my Activities in the activities package, sorted by their functionality. And I have other classes in upper packages.

    When I started this project, I could'nt find any docs about the "best" Android project structure. I'm not sure, that this is a right project structure, but it works.