This article describes how to develop an Android application from the development tool selection, UI interface, picture module, network module, database product selection, performance, security and other aspects. Now sort it out and share it with the majority of Android programmers.
Development tool selection
Development tools I will use Android Studio, which is Google’s official Designated Android development tool. The benefits of Android Studio go without saying. Most of the Android open source libraries on GitHub have been migrated to Android Studio, making it extremely easy to integrate open source libraries when jar files are not available. Most importantly, Google has announced that it will end all Support for Eclipse Android development Tools by the end of the year. So please move to Android Studio soon.
App Design Style
For a developer, this is not a decision. The final decision is in the hands of the product department. In spite of this, I will try my best to persuade the product department to Design the App with Material Design style.
As an Android developer, I have been developing ios-style apps all day. I believe many companies have done so. In order to save cost and time, Android and iOS share a set of UI.
The most common example is a back button in the top left corner of the TitleBar on every page in an Android App. This is mandatory on iOS, but Android has a back button.
I sincerely hope that product designers respect the style and usage of each operating system, and do not design products that are neither fish nor fowl. Material Design provides just such a specification. Since the release of the MD specification, its elegant Design and fresh style has attracted a large number of designers and developers. Now MD Design is not only available on Android (there are already official libraries supporting MD style). Even CSS, HTML, JavaScript web design is becoming popular. Therefore, For the Design style of App, Material Design takes the lead. Maybe you missed Android Design once, please don’t miss Material Design again.
Some related links:
- The Material Design website
- Material Design Color matching template
- MD a design case site
- Android-MaterialDesign-NavigationDrawer mD-style Andorid drawer
- Android- MaterialDesign-DBmz Android- MaterialDesign-DBmz Android- MaterialDesign-DBmz Android- MaterialDesign-DBmz
Versioning support
For the lowest version of Android to support, you can refer to the market share of each version, in fact, the most reliable is based on the statistics of our App to decide, currently our App supports 2.2 minimum. In my opinion, although the 2.x version still has some users, in fact, mobile phones are updated very quickly. For better user experience and the application of updated API (many third-party libraries also have version requirements), the minimum supported version should be raised to 3.0, that is, the API Level should be 11.
App Framework Design
I believe we all know that with the increase of functional modules, App will become bigger and bigger. If there is no good architectural design, the code will become bloated and difficult to maintain, and the coupling degree of each functional module will become higher and higher. Therefore, App can be modularized and a complete App can be divided into several relatively independent modules, which can reduce the coupling between modules and facilitate reuse.
1. Network module
There are very few stand-alone versions of APPS. Most of them need to be connected to the Internet and request data from the server, so the network module is essential. There are also many open source network frameworks on GitHub. Personally, I think open source frameworks can be used. Currently, I will choose okHttp or Volley, and maybe there will be better network frameworks in the future. Note that if you use an open source framework, you must read its source code and be able to navigate it so that you are not helpless when bugs appear. Of course, we can also write the network module by ourselves. At present, the network module of our App is completely written by ourselves. The advantage of this is that we are familiar with the code we have written.
(1) HTTPS support, HTTPS certificate verification (currently many practices are default to allow all HTTPS certificates, in fact, this is not safe, should really do certificate verification)
(2) Support Wap Internet access, mobile, Unicom, telecom agent Settings
(3) Support redirection, data compression transmission, etc
(4) Other noteworthy issues
Writing your own web framework can handle these details perfectly, but the time cost is high. If we use open source frameworks, these details are usually not addressed, so we can make changes on third-party frameworks, which will save a lot of time.
2. Picture management module
Pictures are also an indispensable element in App, and pictures occupy a large amount of memory, so the picture management framework is particularly important. A bad picture framework is easy to cause memory leakage or even crash. Of course, you can realize the image framework by yourself (we are doing so at present), realize the download, decoding, caching and other key links of the picture. My suggestion is to use some good photo libraries, which may be more complete and efficient than our own management of pictures. I would recommend the following image management libraries:
(1) Glide, some of Google’s official apps, such as Google Photos, are used, more explanation?
(2) Fresco, FaceBook’s open source library, supports progressive display of WebP, Gif and JPEG images.
(3) Android-universal-image-loader, before the appearance of the above Image library, seems to be the most popular, before personal App also used it.
(4) Picasso, Square’s open source library, Glide is said to be based on Picasso.
3. Local database module
Maybe your App needs to use a local database, so I suggest you use a popular ORM framework, such as ActiveAndroid or greenDAO, using a third-party library will greatly facilitate your operation of SQLite, I think in the use of the database we need to pay attention to the database upgrade and multi-thread concurrent operation of the database.
4. File management module
An App must involve some files, such as configuration files, images, videos, audio, SharedPreferences files, etc. We can provide a global file management module, responsible for the file add, delete, change, search and other operations. In addition, it needs to support file compression, file upload and download operations, and support multi-threaded concurrent download, breakpoint continuation and other functions for download.
5. Communication mechanism within and between components
For an App, component communication is essential, and the communication type can be divided into point-to-point and point-to-point communication. Point-to-point communication means that only the unique receiver can respond to the message, while point-to-point communication is similar to message broadcast, that is, all registered users can respond to the message. In Android, message mechanism is usually used to implement, but the coupling degree of message mechanism is relatively high. At present, there are also some communication frameworks, such as EventBus, Otto and other EventBus frameworks, which can greatly reduce the coupling between components, but cannot perfectly achieve point-to-point communication. Therefore, it is recommended to use message mechanism and EventBus mechanism together.
6. Data processing framework
In fact, there should also be a data processing framework, when the data request is sent (through the sub-thread), the network module returns data (generally in JSON format), JSON data generally can not be directly delivered to the View layer for use, need to be parsed into the corresponding Model, at the same time, if necessary, but also cache data. These processes can therefore be abstracted into a framework for data processing. The framework can think of accepting the URL of the data request and returning the data Model to the Activity or Fragment. For JSON data parsing, you are advised to use FastJSON, which is fast and stable. The default value is perfect.
7. Thread scheduling module
In fact, there are many operations in Android, such as requesting data, downloading images, clearing the cache and so on, which need to be performed in sub-threads. Often, a Thread is directly used to do so, which will be messy and difficult to manage with too many threads. Therefore, we can abstract out a thread scheduling module, which maintains a thread pool. If there is a need for threads, the thread scheduling module will take threads to do so, which is convenient for unified management. Of course, thread operations in third-party libraries cannot be managed by the thread scheduling module, but other operations involving threads should be handled uniformly.
8. The business layer
The business layer consists of four major components, fragments and Views. It is recommended to use native components as much as possible and use less custom components, because the performance of native components is the best. In addition, IT is recommended to use MVC mode, as long as the design manages its logic well. As for MVP, MVVM and other modes, I think they have defects. In short, I will seek a compromise, there will be gains and losses.
9.APK dynamic loading mechanism
With the increase of App and function expansion, many apps have adopted APK dynamic loading mechanism, which can also be called plug-in. As I have not used in the actual App, so it is not convenient to comment too much. But I personally think this mechanism is very promising, this mechanism will benefit App decoupling, function extension and partial upgrade. Consider a commercial solution: APK Plug-in mobile Application modularization solution and an open source APK dynamic loading framework.
10. Security considerations of App
Few people pay attention to the security problem of Android apps, but it is a serious problem, and some good apps are often cracked. It is suggested to write some core algorithms into a. So library, put important logic in the server side, use encryption for data requests, and at least confuse the code when packaging APK, and also use APK shell mechanism. In short, such preventive measures are never too much.
Writing so much in one breath without logic, there may be omissions, which will be supplemented later. I think if you follow these principles, you can at least make a good App.
If you see this and you think it’s good, give it a thumbs up? If you think there is something worth improving, please leave a message. Will be serious inquiry, correction, thank ~
Finally, for Android programmers, in addition to the above knowledge system, I have sorted out some information for everyone, including but not limited to advanced UI, performance optimization, mobile architect, NDK, hybrid development (ReactNative+Weex) micro app, Flutter and other aspects of Android advanced practice technology; Hope to help you, but also save you in the online information search time to learn, can also share dynamic friends around to learn together!
Need to develop a more detailed architecture study notes system route
Android architecture advanced essential learning resources for free (architecture video + interview topic document + learning notes)