Websocket paused when android app goes to background

前端 未结 1 1312
醉酒成梦
醉酒成梦 2020-12-20 16:57

My android app starts a service that opens a websocket to communicate to a remote server. The service spawns a thread whose run method looks like this.

publ         


        
相关标签:
1条回答
  • 2020-12-20 17:47

    If you want this function to be guaranteed to continue to run while your app's UI is in the background, you will need to make that service run as a foreground service. There are some restrictions/guidelines on the use of foreground services, see the documentation at https://developer.android.com/guide/components/services.html.

    Alternatively, if this is work that needs to occur on a periodic recurring basis and does not need to run continuously, you may be able to utilize JobScheduler; see https://developer.android.com/topic/performance/scheduling.html.

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