Common problem analysis and solution development Android

Recently the company has a new business needs, the need to develop an APP, because I worked on Android APP (I want to tell them that four years ago, trained, trained, trained), put the development task to me, of course, nor is it I am a man, let me set the development team, plainly, is to let me be in charge of technical guidance and a framework to build. I, how can I do, can only bite the bullet and write ah. Indeed a bit Shousheng, so the middle is still experiencing some problems, the following record about it.

1, the log collection

Logging is a common requirement, is important for development and testing, there are many open-source logging tools, can also develop their own, here I chose an open source tool.

Welcome: TLog

2, sub-thread calls Toast newspaper Can not create handler inside thread that has not called Looper.prepare () error

This is a typical thread wrong question. That is the main thread to the UI thread doing UI related operations, network operations UI thread can not, if you need to use to operate Looper.prepare (), Looper.loop (), but if the thread used in the UI Looper.prepare (), then , will report the above error, app will stop.

Difficult problems is how to distinguish between the UI thread and thread the network is very simple, the callback request in the network, is the network thread, the other is the UI thread.

3,Only the original thread that created a view hierarchy can touch its views的问题

The reason: the view component is not thread-safe Android system, if you want to update the view must be updated in the main thread (UI thread) in, not in the child thread (the thread network, time-consuming thread) operations update execution. Handler need to notify the main thread update the UI.

4,Cleartext HTTP traffic to xxx not permitted的问题

The reason: Google said that to ensure the security of user data and equipment for the next generation of Android (Android P) application, the default will be asked to use an encrypted connection, which means that Android P will prohibit the use of all App unencrypted connection, so Android operating system Android P devices either receive or send traffic codes can not be transmitted next, the next required (transport layer security) protocol transport layer security, while Android Nougat and Oreo not affected. HttpUrlConnection be used http request in Android P following exception java.net.UnknownServiceException: CLEARTEXT communication ** not permitted by http network network security policy on the device Android P system, non-encrypted if the application uses plaintext traffic request , the application will not cause the network request, https are not affected in the same manner, if the application nested webview, webview only use https request.

Solution: Configure AndroidManifest.xml file

<application

android:name=".MesApplication"

android:allowBackup="true"

android:icon="@drawable/logo"

android:label="@string/app_name"

android:roundIcon="@drawable/logo"

android:supportsRtl="true"

android:theme="@style/AppTheme"

android:usesCleartextTraffic="true">

</application>

 

Codeword is not easy, if that helps, be sure to give me some praise yo ~ ~

Otherwise, believe it or not I smashed your house lights, midnight kiss you steal (¯ε ¯) !!!

Guess you like

Origin www.cnblogs.com/tonyccc/p/11470093.html