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.