How to organize your Android code structure

Doing things right, and keeping classes single-purpose, will end you up with a lot of files in Android projects. So, organizing your code structure is a popular topic in the community. Also because it's something specific to your projects.

Here are some suggestions:

It's generally a personal preference, as long as it's clear.

Here's what I'm using in my current project:

  • analytics
    • Google Analytics, Facebook Analytics...
  • api
    • API Services (for Retrofit)
    • models
      • API Response/Request models (for GSON parsing)
  • events
    • Bus Provider and Event classes (for Otto)
  • helpers
    • Simple and re-usable general helper classes (Preconditions, PreferencesHelpers...)
  • models
    • Domain related models. These are different from the api.models when the API is from a external source you don't control.
  • services
    • Domain specific services, tightly related with your application business logic (Could also be managers)
  • ui
    • activities
      • Android activities
    • adapters
      • For ListViews and RecyclerViews
    • views
      • Custom views
  • Application class