Download data when internet connectivity is detected

后端 未结 2 535
[愿得一人]
[愿得一人] 2021-01-28 03:44

I want to download some data including json and image(binary data) whenever internet connectivity is available.

I have a full working code which can do that. The problem

2条回答
  •  耶瑟儿~
    2021-01-28 04:10

    Which is the best practice to do so?

    Best way is to use IntentService.

    Start this service from your BroadcastReceiver. Via IntentService, all requests are handled on a single worker thread -- they may take as long as necessary (and will not block the application's main loop), so no worry about how long your task is.

    Is broadcast receiver stays around even when application is not on?

    Yes, if they are registered via manifest.


    Helpful resources are

    1. Creating a Background Service
    2. IntentService Basics

提交回复
热议问题