Android
Author: crossroads links: https://www.jianshu.com/p/230f530b108d disclaimer: this article has been published, it has been approved. Crossroads forward etc. Please contact the author
preface
I have been engaged in Android development for nearly four years, and I suddenly found the remaining mining diary and attention points. I would like to share them here to help you avoid them. Then think of something relevant and add an update. Probably some error-prone points, code optimizations, etc.
A code,
1. Menu
Notice the difference between onCreateOptionsMenu and onPrepareOptionsMenu, don’t abuse it. The menu is in onPrepareOptionsMenu if it needs to be updated, and the inflate menu is in onCreateOptionsMenu.
2. Use the tint
You can use Android: Tint or setColorFilter to change colors without requiring several drawable colors.
3. Rxjava must be used
RxJava is really easy to use and must be used to improve a lot of efficiency, dumb programming is getting closer.
4. Change the background color in Java
(XX.background as GradientDrawable).let { it.setColor(color) it.setStroke(2, color)}
Copy the code
Two, the pits
1. Older versions are compatible
Some back-end interfaces have returned data changes, the database has not been refreshed, and the mobile side has not been compatible, with predictable results. So be sure to consider compatibility with older versions.
2. Don’t be lazy
They didn’t test at that time, they didn’t do pagination testing after they replaced the API, and at that time the old API had pagination, the new API didn’t have pagination, and the result was duplicate data. After enough testing, and then test, this kind of stupid mistake must be avoided. So, again, when you’re testing, pay attention to the critical points, these are the places where you’re prone to errors, like page loading, 30 at a time, and you test for 30, 29, 31 at a time
3. Don’t abuse Refactor
In fact, I only need that one XML file to change. In this case, I should commit the previous changes and then replace them, and then use git status to check the changed files. If not, reset. This kind of global change, which is prone to problems, must be distinguished from the last change, otherwise it will be difficult to restore the previous code if it goes wrong.
4. Note that the URL is in Chinese
When self-stitching URL, pay attention to whether there is Chinese, whether there is the code.
5. Network pictures
When downloading images, it is best to set a default image display to prevent the image empty error
6. The Toolbar is blocked
Using android: fitsSystemWindows = “true”
Code specification
-
Writing code is really not just about writing code, but also about what the requirements are and why and what might happen, so that the code can be more flexible and adaptable to unexpected situations.
-
Git rebase merge creates a new branch every time you develop a new feature.
-
To commit to submit content, you can refer to https://github.com/commitizen/cz-cli style, also can define your own set of rules, such as NEW features, NEW XX, etc.
-
Do not exceed the rightmost line in Android Studio. If it is too long, break it, but do not have multiple line breaks.
-
Never, ever have a function that is too long to be easy to understand. Functions over 100 lines are a disaster. For duplicate code, commission functions.
-
For enumeration types, use comments, such as 1, 2, and 3, to use static string XX=1, better to call XX.
-
Keep development notes, such as the ones I have here, from previous notes, and if you keep track of your development, it’s good for reviewing later. It is also advisable to note the good and bad aspects of your job.
Iv. Development period
For tasks that are too much or too dangerous to complete, check product priorities and synchronize with managers and publishers
Afterword.
Write what comes to mind, so first, although it is a small place to start, but also pay attention to oh.
6 days to modify 1 line of code: A Real-world Software development process
Welcome to contribute ~