1

I am working on an android app that contains two activities. One activity displays details of some .apk files in a list that are hosted on a remote server. When one of the list items is clicked, second activity opens which displays the complete details of the .apk file that was clicked on by the user, like google play store.

Problem

I am able to download and install the .apk file via second activity but problem arises when i destroy the second activity while the download is running. Download completes but the install prompt doesn't shows up because I unregister the Broadcast Receiver, listening for the download complete event of the DownloadManager, when the second activity is destroyed.

Question

What is the best way to handle this problem? I want to be able to download and install the .apk file even when the activity which started the download is destroyed.

Also note that user can also download more than one .apk file at a time just like google play store, so how can I gracefully handle that? so that all the .apk files can download and install one after the other.

  • Use `IntentService` for that. – Chirag Savsani Jan 01 '19 at 07:37
  • As user can download multiple files at the same time, do I have to start the service each time user chooses to download a file even when another file is already being downloaded or I can use the same instance of the service that is already running? –  Jan 01 '19 at 07:38
  • Yes, You can use same instance of Service. – Chirag Savsani Jan 01 '19 at 07:40
  • can you post a sample code? that would really be helpful to understand how this will work? Just a simple code that will show the workflow –  Jan 01 '19 at 07:42
  • Have a look at https://stackoverflow.com/questions/25659657/how-to-download-multiple-files-concurrently-using-intentservice-in-android – Chirag Savsani Jan 01 '19 at 07:45
  • In that link they suggest to use Only service if download is simultaneously – Chirag Savsani Jan 01 '19 at 07:46
  • I am ok with multiples files downloading one after the other, for me, the problem is handling the download requests and then installing file once the downloading of particular file is complete just like to happens on google play store –  Jan 01 '19 at 07:51
  • How you install APK without user interaction? – Chirag Savsani Jan 01 '19 at 07:52
  • I have a `Broadcast Receiver` which listens for download complete event broadcasted by `DownloadManager`, in the broadcast receiver I get the `Uri` of the downloaded file and the install it., –  Jan 01 '19 at 07:54
  • No My question is, How to Install APK without user interaction?" User have to click on install prompt and accept permission right? – Chirag Savsani Jan 01 '19 at 07:58
  • yes that is how it is installed, I want that install prompt to open when the download completes. It does open but the problem is when activity is destroyed, broadcast receiver is unregistered, so install prompt doesn't shows up when download is completed –  Jan 01 '19 at 08:21

0 Answers0