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 包结构最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)