question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support moving download location (e.g., between internal and external storage)

See original GitHub issue

[REQUIRED] Use case description

I’m trying to implement a way for users to switch from internal storage to external storage (e.g. SD card), and I want to preserve all downloads when doing that. I’m releasing the current cache, copying all the files, and creating a new cache pointing to the new directory (I’m using SimpleCache). I’m also creating a new DownloadManager with the new cache, but in the end that doesn’t matter because the DownloadService will still be stuck to the old DownloadManager (pointing to the old cache) thanks to the static downloadManagerListeners that hold the DownloadManagerHelper which holds the DownloadManager.

Proposed solution

Ideally it’d be great if we had an API that would do all the work needed to switch between internal storage to external storage. But if we have a way to simply update the DownloadManager instance held by DownloadService, we’d be able to do the rest ourselves.

Alternatives considered

At first I thought we could simply have a protected method that clears the downloadManagerListeners, but I don’t fully understand its purpose yet, so I’m not sure whether that’s reasonable or not.

On our end one solution is to simply kill the process and restart the app, but that’s definitely overkill and would be far from good to the users.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:17
  • Comments:21 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
janeriksamsonsencommented, Jan 7, 2020

Ability to switch between internal-storage and sd-card would be a very welcome enhancement!

3reactions
tfcporciunculacommented, Sep 2, 2019

Here’s my current reflection code for future reference, since it seems this might be useful for other people:

public static void cleanDownloadManagerReference() throws NoSuchFieldException, IllegalAccessException {
  Field field = DownloadService.class.getDeclaredField("downloadManagerListeners");
  field.setAccessible(true);
  ((Map) field.get(null)).clear();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Move your files to a new Windows PC using an external ...
Learn how to move files to a new Windows PC using an external storage device like a USB drive, SD, card, or external...
Read more >
Transfer files between your iPhone and computer with an ...
Use an external device, such as a USB drive or SD card, to transfer files between your iPhone and computer.
Read more >
Moving your Sync folder to a new location
You can move your Sync folder to a new location on your computer, onto an external drive connected to your computer, or to...
Read more >
SD Card & Device File Transfer | T-Mobile Support
Click Open folder to view files and click OK. Locate the file(s) you want to move. Cut or copy and paste the desired...
Read more >
Move Files from Internal Storage to SD / Memory Card - Verizon
1. From a Home screen, navigate: AppsMy Files. These instructions apply to Standard mode only. 2. Select an option (e.g., Images, Audio, etc.)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found