Some experiences on integrated development of Android + javaee Systems

Source: Internet
Author: User

A long time ago, I heard people say that android will get angry in the future. As a forward-looking person, it will be a good opportunity for transformation. javaweb is too mature and saturated, nowadays, various types of Android mobile phones are emerging on the market, and various online Android video series follow up. Android has become a hot topic, and it is easy to get started at the beginning because of its personal interest, later, I found many problems at work, which were also very difficult. I learned some experiences and patterns from the tangle and pain!

 

1. android, as a view layer, must use the WebService interface to achieve low coupling with the service layer. Currently, there is no perfect plug-in, I have tried axis's Android package (which is also made by myself by an interested party). It is very troublesome to use it, especially the transmission of complex data types, and there are many bugs, changing other people's source code will undoubtedly increase the team's learning cost and Development difficulty. In desperation, the android end uses Apache's httpclient to send interactive requests and define XML interfaces for data transmission, receiving is also parsed using dom4j. It is tested that dom4j supports a lot in 2.2, and less than 2.1 does not support parsing usage, but most of them can be used. You may understand this, yes, the backend uses the servlet mechanism and uses Java reflection to dynamically call the specified spring service and method based on the description of the XML file. This is enough, in addition, you can make more flexible extensions in your own way.

 

2. httpclient is really a good thing, but as a stateless access protocol, HTTP cannot save user session information, so I opened the source code of axis and found that it saved the user's first access information to a specific file. Then, according to the heartbeat mechanism, I checked it regularly, therefore, I saved the user's first access information in the database session table and wrote a stored procedure to delete records whose Logon Time in the session exceeds 30 minutes from the current time, every login, the user matches the session table and does not have a record to immediately time out. This makes it much easier, every time you access the system, you have to carry the serial number, sessionid, that is, the system-assigned ID in the XML file to call it a complete session.

 

3. drawing in the Android system is a troublesome task. In the early stage, our team searched for all the drawing plug-ins, but they were not satisfied with the problem, or they were too troublesome to use, either we couldn't find the expected results, and we had no idea how tired the study was. I asked some old programmers who had previously worked on j2_9. They suggested that if they didn't do professional games, statistical charts are more appropriate with the help of the server, so we abandoned all the Android-side drawing plug-ins and used jfreechart to draw images on the server. The pictures are displayed on the mobile phone through HTTP, of course, because the 2.1 system does not support flash, it is not considered to be more beautiful, and the chart is intuitive and clear.

 

4. UI is a difficult issue, and in order to adapt to different resolutions, it was very difficult to use PX units before. Later, we changed the dip positioning and improved a lot. After that, we used the tab style in a large area and unified the style, which had many difficulties, for example, you can add a style to the tabhost to dynamically change the effect. The buttons are transparent. The listview uses a horizontal line and an arrow to add a dynamic shiny display and drop-down pages, as well as gesture sliding, various widget effects and animation screen cutting, in order to avoid detours, We decompiled all mainstream Android la S and beautifying usage such as QQ, Feixin, 58, Yuji, plane ticket, and moji.com, and learned a lot of useful experience, however, I still feel that the layout is very difficult. The artist cannot directly intervene and the simulator test is not very powerful. I can't just use a real machine to test the UI, and the speed is much faster.

 

5. the android client updates the feature. I believe that only those who have done so will be aware of the bitterness. First, we must do a good job of resumable data transfer, second, do a good job of database initialization, and third, do a good job of signature, 4. Do a good job of version verification algorithms and display the dynamic progress bar and percentage. Do a good job of resumable data transfer, but it is troublesome to initialize the database, our practice is to copy the SQLite library file directly from raw to the SD card, and set the SQLite library reading path to point to it. It feels better that the signature is unknown at the beginning, the installation is not completed every time the app is overwritten. Later, I realized that to ensure the uniqueness of the app, it is like an ID card. The other has no effect. It is not the same as the signature of Saipan, APK encapsulation must be in the same signature file to overwrite and install each other!

 

6. webview can call back-end Java code, similar to the DWR function. However, this function has been rarely used and is unstable. Compatibility considerations should be taken into consideration. Since Android provides so many UI controls, it means that webview cannot replace it. After all, you still need to call the underlying service, and webview should be used with caution.

 

 

7. android should also follow the MVC programming specifications. activity is only responsible for jump, UI, and simple data verification. business logic is placed in the service class, And SQLite operations are slightly encapsulated, create a template class similar to jdbcutil, and provide methods such as adding, deleting, modifying, and querying pages. In this way, DaO operations are improved a lot. I want to be a Java programmer for Android development, the biggest obstacle is not that the framework is not the APIs in Google SDK, but the Java Foundation. By writing programs, it is found that programmers who develop mobile phones have excellent basic qualities, especially in collections and threads, exceptions, Io, and HTTP must be very thorough. Otherwise, a seemingly simple function may write hundreds of bugs, even with low efficiency and poor readability, basically, I can't understand what I wrote, and I am familiar with the basic structure of class packages, including the writing of interfaces and abstract classes, including anonymous internal classes, optimize and reconstruct the code for the functions you have completed in a timely manner, so that you and others can read the functions as if reading poetry, which is clear and elegant. It is not as mature as the Web framework, and everyone uses ssh, there are many rules to follow, You can't see your skills in painting! I want to talk about programmers who want to develop Android. Pay special attention to the Java basics!

 

8. in addition, map navigation is also a bright spot. Now, no matter what features you do, you will use map navigation, have fun, and want to know where you are. Baidu Google has released the android map interface, we use ArcGIS. Fortunately, there are not many applications in the API, and there are ready-made examples on the official website. This makes it possible for me to turn off the issue of ArcGIS with two brushes.

 

9. the biggest tangle of writing Android code is testing and finding bugs. The simulator is very slow. No matter where it is modified, re-compile and deploy it. The ADT plug-in often experiences debugging failures and wants to accelerate development, first, we should turn off eclipse automatic compilation, kill useless processes in the simulator, and then turn off some useless mobile phone special effects for modular development, in this way, the entire method is easily split into JUnit for testing. There is a youwave_android simulator, which is very fast to use. If there is no real machine, you can use it for the transition, if nothing happens, you can download more Android software and learn how other people's systems do it. At least it can improve the UI aesthetics. Some people propose to develop it on the Linux platform, if you have never used it before, it is best not to make it difficult. I really want to try to recommend the ubuntu10 Chinese desktop edition. Although the speed is not much faster, it is indeed a good opportunity to gradually improve yourself, more technical skills are not overwhelmed!

 

10. some tips are quite practical, and some ADB commands must be faster than using the ADT plug-in. The new SDK upgrade package puts it under the platform-tools directory; the keyboard shortcut Ctrl + F11 or keypad home is available for horizontal and vertical screen switching. If your debug fails, try to kill the process in ddms and try again. If not, restart the simulator; if you suddenly find that the R. if the Java file is ready, show problems to check whether there is an error in the project. Generally, it is not because the package path is faulty or the internal layout file of the program is incorrect. If it is still invalid, close eclipse and re-open it, sometimes the ADT will have such a bug. The ADT plug-in and SDK upgrade packages are version dependent. If you are using more than 8.0 ADT plug-ins, remember that the SDK upgrade package must be updated with the latest version, otherwise, an error will be reported that the ADB command cannot be found. Do not upgrade the plug-in. The latest 10 plug-ins can only run on more than 3.5 of eclipse, and it does not bring many surprises, only later SDK versions are supported; Andro The ID program itself is also flawed. Do not drill too deep and compete with it. If you cannot go, you will want other paths. As long as it is simple, simple, and unconventional, the program functions are robust; in addition, I have to add a few more Android developer forums to post source code for help. I have no technical skills!

 

Although Android is very popular at present, I heard that the Linux community administrator has deleted the Google Android source code and said it is not completely open-source, and there is a suspicion of using the open-source community. If so, therefore, Android will lose the trust and support of many developers. In short, it is not a good result. I sincerely hope that the next time Google Baidu sees not a lot of Hello world examples pasted by copy, it is actually the experience shared and transferred between developers, so open source is the final truth!

 

Finished!

If you have any questions, please join the group number for discussion: 173711587

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.