Friday, February 14, 2014

Structural problems backstage Service Service


Now a small project, you need to write a background of Service Service, Service to start automatically at boot, the main function is to read the sensor Service data, socket services are also written in the Service.
The problem is you want to get data from the UI Service, should bindService, then when the first switch UI's first Activity Service Solutions and tie, and then get a second Activity bound, so that Service is equivalent to destroy immediately after they onCreate, equivalent to just switch interface, socket must disconnect and reconnect. Is there any other structure to solve this problem it.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Under normal circumstances you jump to another screen, even if access to the original meaning of the data is not big.
1 You can not close the Socket, continues to run but no data is passed to the original Activity in the background.
2 You use the radio to replace bindings registered broadcast Activity inside, as long as there is data acquisition sends broadcasts.

Socket This fact is not closed in Service inside.
Reply:
cited a floor birdsaction reply:
under normal circumstances you jump to another screen, even if access to the original meaning of the data is not big.
1 You can not close the Socket, continues to run but no data is passed to the original Activity in the background.
2 You use the radio to replace bindings registered broadcast Activity inside, as long as there is data acquisition sends broadcasts.

Socket This fact is not closed in Service inside.


Destroy all the Service, Socket thread can survive it.
I think radio is really no way to reuse
Reply:
Bind if you do not, do not display the call stopService,
The Service is not going to stop the run, and will not Destory.


Reply:
Your Service is a boot on startup, you can be completely passed Activity data broadcasting.
Reply:
references, 4th Floor birdsaction reply:
Your Service is a boot on startup, you can complete the data to be broadcast Activity
<. / fieldset>

I am using the Messenger, broadcast point it is more convenient
Reply:
Messenger is possible, but the essence is also Bind way, it is recommended to use the broadcast.
Just sign up for a broadcast Activity, fine.
Reply:
reference to the third floor birdsaction reply:
Bind if you do not, do not display the call stopService,
The Service is not going to stop the run, and will not Destory.


When the application is closed, Service calls onDestroy
Reply:
Applications are closed, and you want to get the data? Take data to the UI display?

If you do not want to close the Service, you can open the Service independent process.
Reply:
reference to the 8th floor birdsaction reply:
applications are closed, and you want to get the data? Take data to the UI display?

If you do not want to close the Service, you can open the Service independent process.


Say it specifically, Service is, app, app on the phone set-top box is to obtain data from the Service set-top box, so the Service should have been running in the background.
The Service is not the boot process is independent of what is required to write a separate Service's apk?
Reply:
reference to the 6th floor birdsaction reply:
Messenger is possible, but the essence is also Bind way, it is recommended to use the broadcast.
Just sign up for a broadcast Activity, fine.


I switched to broadcasting, the preparation process must be found for each Activity dynamically register a broadcaster, is there a method to simplify it down
Reply:
Services completely separate activity, do not bind up, and then notified via a broadcast message activity can be
Reply:
Really lazy, you have to accept what the message, customize your own, of course, need to register, which also do not want to write?
Reply:
reference to the 12th floor guoke204 reply:
really lazy, you have to accept what the message, customize your own, of course, need to register, which also do not want to write?


Not too lazy, I want to make the interface, broadcasting can not do so. Has now been changed to broadcasting, indeed better than the bind!

No comments:

Post a Comment