Android engaged in development for six years, those things I learned!

Android engaged in development for six years, those things I learned!

For six years, I have written a number of companies for a variety of applications. You write code or handling code libraries and cultural way as you would experience constantly changing.

Your code quality should be improved with experience, otherwise you will need to reflect on.

Choosing the right architecture

If you are developing an application from scratch, then there will be a lot of advantages.

One of them is choosing the right architecture. In general, we prefer to everything written in the same activity file because to do so easily. But when your code amount increases, it will be a problem. Your code base will become very large, the number of lines of code contained in each file will be very large.

For performance and maintenance of the code, choosing the right architecture in the early stages, it is the sensible approach.

Many architecture MVC, MVP, MVVM and MVI and other help Android developers to easily maintain, test and develop new features.

Android engaged in development for six years, those things I learned!

The figure illustrates the After designing the application, all modules should be how to interact with each other. Although it all depends on your organization, but you may also have the opportunity to choose the architecture for your application.

However, we strongly recommend that you select a specific architecture to fit your needs.

The best architecture on which this topic is controversial.

According Developer's Guide:

"No single method can apply to write the best application in each case. Having said that, for the most part and workflow, this recommended architecture is a good starting point."

Put to good use Android Studio

Android Studio provides the fastest tools to build applications for each type of Android device.

 Unfortunately, we have only explored a small part of the IDE. Android Studio comes with many tools, the following are the tools we use in our daily development.

Visual Layout Editor

In this Layout Editor, we can design a UI element onto the visual editor, and in order to quickly build the layout, while eliminating the need to manually write the layout XML.

This can preview the layout design editor on a variety of Android devices and versions, but you can also dynamically adjust the size of the layout, in order to ensure normal work on various screen sizes.

When you use this Layout Editor to build a new layout, in particular, you can feel the power of it.

APK Analyzer

我们可以利用 APK Analyzer 减少花在调试应用程序内DEX文件和资源问题上的时间,而且还可以减小APK的大小。此外,你还可以在命令行中使用 APK Analyzer 。

APK Analyzer 的功能包括:

  • 查看APK中文件的绝对大小和相对大小,例如DEX和Android资源文件。

  • 了解DEX文件的组成。

  • 并排比较两个APK。

Android engaged in development for six years, those things I learned!

Fast Emulator

如果你需要应对各种版本的 Android, 而且还希望在各种 API 级别上测试你的应用,那么这款模拟器甚至比真正的设备还好。

这款模拟器提供了Android设备所具备的所有功能。你可以模拟打电话和发短信、指定设备的位置、模拟不同的网络速度、模拟旋转和其他硬件传感器、访问 Google 应用商店等等。

与在物理设备上的测试相比,从某种程度上来说,在模拟器中测试应用程序更快捷、更方便。

Profilers

Android Profiler工具提供了实时数据,可以帮助你了解应用使用CPU、内存、网络和电池资源的情况。

Android engaged in development for six years, those things I learned!

虽然我们有各种的分析器,例如CPU分析器、内存分析器、网络分析器和能耗分析器。

但 Android Profiler 可以兼容Android 5.0(API级别21)及更高版本。你可以使用 Android Studio 中的高级事件探查器来监视应用会话消耗CPU资源和内存的状况。

内存探查器可以帮助我们使用Leak Canary调试内存泄漏。

配置构建变化

你可以使用构建变化为你的应用创建不同的版本,还可以正确管理依赖项和签名配置。

大多数组织都有测试和生产环境。如果想针对每种环境构建不同的应用程序,你可以利用不同的构建类型指定不同的基本URL。

Android engaged in development for six years, those things I learned!

你还可以根据API级别或其他设备变化,为不同的设备构建应用程序的不同版本。

使用 Lint Checks 改进代码

这个 lint 工具可以帮助你找出结构不良的代码,而这些代码可能会影响应用程序的可靠性和效率。

Lint会告诉你布局中是否存在占用大量空间的命名空间。

它还告诉你其他结构性的问题,例如使用了弃用的元素或目标API版本不支持的API调用。它还会建议你使用所有库的最新版本。

使用新的 SparseArray<String>(...) 代替 HashMap,可以获得更好的性能。SparseArrays 会将整数映射到对象。与普通的对象数组不同,下标间可能存在间隙。

它比使用 HashMap 将整数映射成对象的效率更高。

测试应用程序

测试驱动的开发(TDD)是确保你会测试每一行新代码的一种方法。如果采用这种方式,那么在编写要实现的代码之前,你需要为添加的内容编写测试。

由于时间和资源有限,大多数创业公司可能不会采用测试驱动的开发环境。但是它已被许多公司广泛接受。

Android engaged in development for six years, those things I learned!

Android 有三种类型的测试。

1.单元测试

单元测试用于测试方法和小模块。无需模拟器或真实设备即可运行这些测试,因为它们可以在JVM上运行。

JUnit 和 Robolectric 是流行的 Android 单元测试框架,可以在JVM上快速运行测试。

2. 设备测试

设备测试依赖于Android 框架。由于这种依赖性,你需要模拟器或物理设备才能运行这种测试。我们使用 Mockito 模拟设备测试中使用的对象。

3. UI测试

我们可以利用UI测试活动的启动是否正确,或视图的存在是否正确。Espresso和UI Automater 是UI测试中广泛使用的工具。

以下是应用当前所包含测试的软件包结构。

Android engaged in development for six years, those things I learned!

Test:单元测试都保存在这个文件夹中。这些测试在JVM上运行,不需要 Android 设备或模拟器。

Android test:所有设备和UI测试都保存在这个文件夹中。这些测试需要 Android 物理设备或模拟器才能运行。

使用版本控制

Git 和 BitBucket 是最常用的版本控制系统。

版本控制可以跟踪文件的改动,可以记录完成的操作,并且可以根据需要恢复特定版本。

但给你与团队一起工作时,版本控制有利于协作,而且还可以将所有的更改合并到源代码中。如果没有版本控制,则你需要进行备份,并将代码存储到安全的地方。

有了Git以后,代码就安全了。你可以跟踪更改,还可以针对某次发布维护多个代码库。它可以简化两个人一起工作时合并代码的工作。

此外,你也可以利用Git展示你的工作,并向许多开源项目贡献代码。Git已成为许多公司筛选人才的地方,因为他们可以通过Git查看候选人的工作成果和个人项目。 

发布产品的知识

无论你是否是将新版本发布到生产环境的主要负责人,我都建议你掌握将应用发布到应用商店的方法。

掌握使用密钥存储文件对APK进行签名的方法。记下你的密钥库密码和别名。你甚至可以在Gradle文件中配置它们,以简化签名过程。

使用 Crashlytics

Crashlytics 是最强大,最轻便的应用崩溃报告解决方案。

Crashlytics 提供了深刻且可付诸行动的见解,甚至包括应用崩溃时确切的代码行号。你可以使用 crashlytics 来减少识别故障和修复故障的时间。

此外,它还提供了各种分析报告,例如出现频率最高的崩溃,崩溃百分比等等。

Crashlytics 还包括 Crashlytics Beta,该服务可以让你轻松地将预发行的 iOS 和 Android 应用分发给测试人员,以便快速获得反馈。

对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!

好了,希望对大家有所帮助。

接下来是整理的一些Android学习资料,有兴趣的朋友们可以关注下我【主页的简介】查看免费领取方式

①Android开发核心知识点笔记

Android engaged in development for six years, those things I learned!

②对标“阿里 P7” 40W+年薪企业资深架构师成长学习路线图

Android engaged in development for six years, those things I learned!

③面试精品集锦汇总

④全套体系化高级架构视频

Android learn more succinctly video after you have received is even more powerful! Enter BATJ manufacturers, etc. (preparing for)! Now say the Internet winter, in fact, nothing more than you get on the wrong bus, and wear less (skills), and if you get on to the car, their technology is robust enough to replace the cost of large companies, how could be laid off, have Curd is out of the business end of it! Now flooding the market junior programmer, set of tutorials for the Android development engineers 1--6 years of staff, is in a bottleneck, after years want to break their own salary increase, advanced Android senior architect for you is themselves, and receive it as soon as possible!

Android engaged in development for six years, those things I learned!

[HD brain diagram above], and [supporting] PDF technology architecture can add me wx: X1524478394 free access

Guess you like

Origin blog.51cto.com/14332859/2460452