Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android package organization

Tags:

java

android

I am fairly new to Android development, so I have some questions about Android project/code design.

  1. Do people generally split up API calls into a separate class/classes? Or do you call them within the object itself?
  2. Are packages just sub-directories? From what I understand, they're only used for the benefit of the programmer as an organizational tool.

I know that these questions are somewhat subjective, but I'm interested in how other developers organize their code. Thanks!

like image 666
adao7000 Avatar asked Jun 18 '15 17:06

adao7000


People also ask

How do I organize my Android projects?

Android applications should always be neatly organized with a clear folder structure that makes your code easy to read. In addition, proper naming conventions for code and classes are important to ensure your code is clean and maintainable.

What is the directory structure of Android?

xml: Every project in Android includes a manifest file, which is AndroidManifest. xml, stored in the root directory of its project hierarchy. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components, and its requirements.

How is an Android project organized in Android Studio?

When you start a new project, Android Studio creates the necessary structure for all your files and makes them visible in the Project window on the left side of the IDE (click View > Tool Windows > Project). This page provides an overview of the key components inside your project.

What are the packages in Android?

A package is basically the directory (folder) in which the source code resides. Normally, this is a directory structure that uniquely distinguishes the android application; such as com. example. app.


1 Answers

Ad packages organization - I develop applications for Android about two years and I have organized source similarly as Andrea Cinesi wrote. But this week I started thinking if it would be more appropriate to package was as application module, for example:

com.example.android
.car
  CarActivity
  CarListFragment
  CarDetailFragment
  CarListAdapter
  ...
.route
  RouteActivity
  RouteListFragment
  RouteDetailFragment
  RouteListAdapter
  ...
.utils
.services
etc.

I'm not yet thinkin twice what all shoul be in "module" (e.g. data entity). But why I'm thinking about this changing? Because in middle or large projects are very much activities / fragments / etc. in one package - and this is confusing to me - I see it especially for larger projects acquired from other developers.

And one more advantage can be divided into module packages - java package-private visibility of methods.

I am not yet decided whether to use this or that variant, but I think for smaller projects do not care and for middle or big project it may be preferable option packages as modules.

like image 194
Petr Daňa Avatar answered Sep 28 '22 08:09

Petr Daňa