Search code examples
androidandroid-intentbroadcastreceiverandroid-serviceandroid-download-manager

Receiving intent if the activity/app is destroyed


I am developing an app where I need to download a large mp3 from an URL and when it has completed update a database with the path where it has been stored, so that in case there is no internet connection the user can play it. I have thought in using the downloader system service which is pretty easy to use. After the download is completed, the service broadcast an intent "download.finished". If the app is created, I would receive the intent via a broadcast receiver and update the database. But I dont know what to do in these situations:

  • What if the system or user has destroyed the activity/app where the broadcast is created. Would it receive the intent?

  • In case it would receive the intent, it would have no sense since the broadcast is hold in a process that would be already kill.

  • Is there any way to make the app wait until the broadcast has received the intent?

I would appreciate if you could tell me if I am doing well or there is a better and cleaner way to resolve this.

P.S.: I ve thought implementing my own download service, but since there is already one which comes with the systems, it would be a good way to save time and avoid boilerplate. Thanks.


Solution

  • What if the system or user has destroyed the activity/app where the broadcast is created. Would it receive the intent?

    An activity would never receive a broadcast. A BroadcastReceiver receives the broadcast. If that BroadcastReceiver is registered in the manifest, your app will receive it, even if the app's process from before had been terminated -- Android will fork a fresh process for you.

    Is there any way to make the app wait until the broadcast has received the intent?

    Not for any common definition of "make the app wait".