Saturday, February 22, 2014
android little idea of maintaining tcp connection, find discussion
Tcp connections are time-consuming to maintain the IO operation, first of all we can be sure that we use to thread, some would say use the service, but the service is running on the main thread (the main thread to handle UI operations) on, so in Services in processing time-consuming operation will cause the main thread blocking.
After determining the thread, we have to determine the position of the thread is enabled, first of all, if used activities (generally more than one application in an activity) which, contrary to this principle with android design activities mainly deal with UI, so the thread can only put Among services, we need to solve the following two problems: communication and synchronization, the first problem is the communication between the activities and services, as well as communication between threads in the activity. Communication between services and activities by Binder, activities and threads is to use the Handler and Looper. Communication is quite good solution, followed by synchronization problems, this has made me very confused, first android among a number of API calls seemingly not executed sequentially, so basically rely on synchronization test, there is no big God can provide some method of synchronization.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Android API which is not the order?
Reply:
How much trouble, threads, and what good service contradictory.
1. Doing a service, start a thread in the service inside
Socket connection
2. Started threads inside3 After receiving socket messages, simple way to point out directly Broadcast, complex point, find a place to save it, and then each time the Activity onStart bind to the service, the message received from the service before the acquisition, etc.
Reply:
You say that white is the communication between services in different thread data transfer
As the thread synchronization should be passed to the Activity UI to change it so that these data can Baidu no difficulty
Reply:
This can be, and I had socket communication is to use this method!
Reply:
really start a thread in the service to perform time-consuming operation!
Reply:
API bind service is like that, sometimes the next sentence of this code is executed, but the service still does not return
Reply:
The API is engaged in, they do not know specifically what to do, so it leads to so many problems
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment