{"id":26047748,"url":"https://github.com/lchristmann/demoworkneverhavinginternetinbg","last_synced_at":"2026-04-17T23:05:01.848Z","repository":{"id":280510763,"uuid":"942162572","full_name":"lchristmann/DemoWorkNeverHavingInternetInBg","owner":"lchristmann","description":"Minimal android application problem implementation for the StackOverflow question \"Why does my WorkManager Work never have Internet connection when running in the background?\"","archived":false,"fork":false,"pushed_at":"2025-03-03T20:01:49.000Z","size":102,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T21:20:17.153Z","etag":null,"topics":["android-application","permission-android","retrofit2-kotlin","stackoverflow-questions","workmanager-kotlin"],"latest_commit_sha":null,"homepage":"https://stackoverflow.com/q/79478376/20594090","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lchristmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-03T17:12:28.000Z","updated_at":"2025-03-03T21:06:56.000Z","dependencies_parsed_at":"2025-03-03T21:20:18.959Z","dependency_job_id":"2794d2fc-cf12-4778-b845-d6f292a0bdbe","html_url":"https://github.com/lchristmann/DemoWorkNeverHavingInternetInBg","commit_stats":null,"previous_names":["lchristmann/demoworkneverhavinginternetinbg"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2FDemoWorkNeverHavingInternetInBg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2FDemoWorkNeverHavingInternetInBg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2FDemoWorkNeverHavingInternetInBg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2FDemoWorkNeverHavingInternetInBg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lchristmann","download_url":"https://codeload.github.com/lchristmann/DemoWorkNeverHavingInternetInBg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242473055,"owners_count":20134021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-application","permission-android","retrofit2-kotlin","stackoverflow-questions","workmanager-kotlin"],"created_at":"2025-03-07T23:13:39.468Z","updated_at":"2026-04-17T23:05:01.738Z","avatar_url":"https://github.com/lchristmann.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A minimal demo of the problem presented in the StackOverflow question [Why does my WorkManager Work never have Internet connection when running in the background?](https://stackoverflow.com/q/79478376/20594090)\n\nThe goal: do API requests in the background with WorkManager using the Internet.\n\nThe problem: it doesn't seem to work for me.\n\nHow this app proves that point: When you click the button \"Schedule work with 15s delay\"...\n\n- ... if you leave the app open on-screen (\"in the foreground\"), the worker has Internet connection and does a successful POST request\n- ... if you put the app in off-screen (\"in the background), the worker has no Internet connection and fails the POST request\n\nThis can be traced by testing this (leaving app in foreground vs. putting it in background during the 15s work delay) and looking at the Logcat.\n\n## Technology used\n\n- [Android WorkManager](https://developer.android.com/develop/background-work/background-tasks/persistent/getting-started) for background work\n- [Retrofit HTTP client](https://square.github.io/retrofit/) for HTTP requests\n- [restful-api.dev](https://restful-api.dev/) for free REST endpoints for demo projects\n\n## What this minimal problem implementation consists of\n\nSee the single Git commit `add minimal problem implementation` for all that is changed compared to a newly generated Empty Activity project.\n\n## Steps get this up and running\n\nJust build the project and run the app.\n\nMake sure your emulator is at least API-level 29 (this is the `minSDK`). I use the Pixel 7 API 35.\n\n## Observe this\n\nClick the button \"Schedule work with 15s delay\" in the application.\n\nWhen you leave the app like this, open on-screen and wait for 15s, the Logcat will say:\n\n```text\nNetwork available: true\nGET Response: {\"id\":\"7\",\"name\":\"Apple MacBook Pro 16\",\"data\":{\"year\":2019,\"price\":1849.99,\"CPU model\":\"Intel Core i9\",\"Hard disk size\":\"1 TB\"}}\n```\n\nWhen you put the app in the background (e.g. swipe it up and chill on the home screen), the Logcat will say:\n\n```text\nNetwork available: false\nGET request exception: Unable to resolve host \"api.restful-api.dev\": No address associated with hostname\n```\n\n### Edit: Sometimes it works, but not reliably\n\nI've observed times, where it works.\n\nBut very often it does not work.\n\nIt looks like a coin-flip. I fail to understand why.\n\nE.g. in one try that I just did while writing this, I am staying in Chrome Browser in the foreground, with the work scheduled in the background, and I get those logs:\n\n```text\nNetwork available: false\nGET request exception: Unable to resolve host \"api.restful-api.dev\": No address associated with hostname\nWorker result RETRY for Work\n\nNetwork available: false\nGET request exception: Unable to resolve host \"api.restful-api.dev\": No address associated with hostname\nWorker result RETRY for Work\n\nNetwork available: true\nGET Response: {\"id\":\"7\",\"name\":\"Apple MacBook Pro 16\",\"data\":{\"year\":2019,\"price\":1849.99,\"CPU model\":\"Intel Core i9\",\"Hard disk size\":\"1 TB\"}}\nWorker result SUCCESS for Work\n```\n\nIf you can get it to work reliably, this problem would be solved.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flchristmann%2Fdemoworkneverhavinginternetinbg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flchristmann%2Fdemoworkneverhavinginternetinbg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flchristmann%2Fdemoworkneverhavinginternetinbg/lists"}