android.os.NetworkOnMainThreadException on service start on android

前端 未结 4 1263
忘了有多久
忘了有多久 2020-12-11 16:40

after trying my brand new service on android i get this:

i guess is something related to the manifest file and permissions, the service is started after the last act

4条回答
  •  余生分开走
    2020-12-11 17:08

    As per the documentation, even though you use a Service to perform long running operations, the Service itself runs on the application's main thread. So you have to spawn a new thread to perform potentially long running tasks like network access.

    Android's StrictMode actually checks for network operations performed on the main thread and throws a NetworkOnMainThreadException.

提交回复
热议问题