Android 包结构最佳实践

时间:2023-01-31
本文介绍了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 在已删除的包中没有收到 Intent ACTION_PACKAGE_REMOVED 下一篇:如何在 Android 中使用 XML 从库中的另一个包中引用字符串?

相关文章

最新文章