Android 包结构最佳实践

Android Package Structure Best Practice(Android 包结构最佳实践)
本文介绍了Android 包结构最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

这篇关于Android 包结构最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
How can i use MYSQL database connection in iphone application useing cocos2d?(如何在使用 cocos2d 的 iphone 应用程序中使用 MYSQL 数据库连接?)
Smoothly drag a Sprite in cocos2d - iPhone(在 cocos2d 中平滑拖动一个 Sprite - iPhone)
CCScrollView scroll and touch events never firing(CCScrollView 滚动和触摸事件永远不会触发)
removing jagged edges of my ropes using antialiasing of OpenGLES(使用 OpenGLES 的抗锯齿去除绳索的锯齿状边缘)
cocos2d Moving between scene(cocos2d 在场景之间移动)