Using an Android Service to handle a network connection

前端 未结 3 1658
误落风尘
误落风尘 2021-01-03 03:21

I\'m working on an Android app that needs to maintain a network connection to a chat server. I understand that I can create a service to initiate the connection to the serve

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 04:14

    Did you check the Service API page: http://developer.android.com/reference/android/app/Service.html ?
    It has a couple of examples on how to interact with a Service.

    The service runs on the same thread and the same Context as the Activity. Check also here: http://developer.android.com/reference/android/content/Context.html#bindService%28android.content.Intent,%20android.content.ServiceConnection,%20int%29

    Finally, take a look also at Lars Vogel's article: http://www.vogella.de/articles/AndroidServices/article.html

提交回复
热议问题