Android service for TCP Sockets

后端 未结 1 1809
天命终不由人
天命终不由人 2021-01-01 03:17

Based on a suggestion in a previous question I asked on here, I\'m trying to push my socket connection for an application that I\'ve written into a service. I spent the bet

1条回答
  •  执笔经年
    2021-01-01 03:50

    This is due in large part to the fact that I guess I still don't quite understand what advantages running in another 'process' is going to give me.

    Generally, none. You create a remote service if you are expecting other applications to communicate with the service. If it will only be used by your own application, use a local service.

    Also, a remote service has nothing to do with creating a separate process within your application.

    Will I potentially see better performance that way?

    You will see worse performance that way, due to extra memory consumption.

    My limited understanding is that by putting it in a different process, the service will run independently of whatever activity I have running on my app.

    Services have a lifecycle independent from activities regardless of whether it is local or remote.

    So would a local service be the way to go for me?

    Sounds likely.

    After the playing I did yesterday, I could not figure out how to pass the data that it reads to the actual "client" (either bound client by remote service, or local client itself) in "realtime".

    Use the local binding pattern, and have the activity call an API on the service to register (and unregister) an event listener. Have the service pass the data to the activity via the listener.

    0 讨论(0)
提交回复
热议问题