用户登录
用户注册

分享至

Android 包结构最佳实践

  • 作者: 蓝血鲎
  • 来源: 51数据库
  • 2022-12-30

问题描述

我对应用程序包结构的最佳做法有疑问.

I have a question regarding best practices for application package structure.

我观看了 Reto Meier 的 Google I/O 2011 演讲 "Android Protips: Advanced Topics for Expert Android Developers" 并阅读他的博文"A Deep Dive Into Location" 并注意到他的应用程序包结构:

I watched Reto Meier's Google I/O 2011 presentation "Android Protips: Advanced Topics for Expert Android Developers" and read his blog post "A Deep Dive Into Location" and noted his application package structure of:

com.... .content_providers
com.... .receivers
com.... .服务
com.... .UIcom.... .UI.fragments
com.... .utils
com.... .utils.base

com. ... .content_providers
com. ... .receivers
com. ... .services
com. ... .UI com. ... .UI.fragments
com. ... .utils
com. ... .utils.base

这是包的首选结构吗?有更好的结构吗?

Is this the preferred structure for packages? Is there a better structure?

推荐答案

打包类的主要目的是简化源代码的导航.这对于开源应用程序尤其重要.在我看来,一个易于导航的包结构包括以下几个包:

The main goal of packaging your classes is to simplify the navigation through your source code. This is especially important for open source applications. In my opinion, a easy-to-navigate package structure includes the following packages:

com.example.main - 包含您的主要驱动程序功能,例如您的主要活动、您的应用程序类(如果有的话)等

com.example.main - contains your main driver functions, such as your main activity(s), your application class (if you have one), etc

com.example.conf - 包含您的配置文件,例如那些包含常量(静态最终变量)的配置文件

com.example.conf - contains your configuration files, such as those containing constants (static final variables)

com.example.net - 与网络相关的类,例如发出 http 请求的类

com.example.net - network-related classes, such as those that make http requests

com.example.util - 实用程序类,例如服务、BroadcastReceivers 或其他后台进程

com.example.util - utility classes, such as services, BroadcastReceivers, or other background processes

软件
前端设计
程序设计
Java相关