Share via

downnload process aborted when Maui Andriod is not visible or screen id turned off

Qun Shen 65 Reputation points
2026-03-07T02:06:24.94+00:00

I have Maui Andriod app, in which a file id dowloaded from an url. When the app is running and visible download process goes well. but screen is turned off or app is not visible, the download process is aborted. Is is greatly appreciated if somene can help me to solve the problem. Thank you!

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Answer accepted by question author
  1. Nancy Vo (WICLOUD CORPORATION) 880 Reputation points Microsoft External Staff Moderator
    2026-03-09T02:59:42.11+00:00

    Hi @Qun Shen ,

    Thanks for reaching out.

    I suggest using Android's DownloadManager which allows downloads to continue even when the app is closed or the screen is off.

    While this is a non-Microsoft link, it’s official Android documentation and is safe to visit.

    Here are the steps and code examples:

    1. We create interface in shared code.
    public interface IDownloadService
    {
        void StartDownload(string url, string fileName);
    }
    
    1. Next, implement in Platforms/Android.
    using Android.App;
    using Android.Content;
    using Android.Net;
    
    public class DownloadService : IDownloadService
    {
        public void StartDownload(string url, string fileName)
        {
            var dm = (DownloadManager)Platform.CurrentActivity.GetSystemService(Context.DownloadService);
            var request = new DownloadManager.Request(Uri.Parse(url));
            request.SetTitle("Downloading...");
            request.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, fileName);
            request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
            dm.Enqueue(request);  // starts download
        }
    }
    
    1. Don't forget to register in MauiProgram.cs.
    builder.Services.AddSingleton<IDownloadService, DownloadService>();
    
    1. Call it.
    await downloadService.StartDownload("https://example.com/file.zip", "file.zip");
    

    NOTE: Internet permission is required in your AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" />

    Hope this helps. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance provide feedback. Thank you.


2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 83,581 Reputation points Volunteer Moderator
    2026-03-07T16:33:20.5833333+00:00

    Mobile O/S are getting more restrictive on what resources can be used when the app is not active. As suggested you can move the download to a background task, but there is no guarantee that the background task will be given enough resources to complete the download. So the app needs to track the download process and allow restarting.

    0 comments No comments

  2. Q&A Assist
    2026-03-07T02:06:39.5166667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    On Android, .NET MAUI apps don’t keep running arbitrary work indefinitely when they’re not visible. When the app is deactivated, stopped, or the device screen is turned off, the app can be suspended or killed by the OS, which aborts in‑process downloads.

    To keep a download running reliably when the app isn’t visible, the work must be moved out of the foreground UI flow and into an Android background mechanism that’s designed for long‑running operations, for example:

    1. Use a foreground service with a notification for long downloads.
    2. Use WorkManager (or a similar job scheduler) to run the download as background work.
    3. Persist progress and support resume so that if the app is stopped and later restarted, the download can continue from where it left off.

    In MAUI, the UI thread and lifecycle events (Created, Activated, Deactivated, Stopped, Destroying) are intended for UI and short operations. Long network operations that must survive screen off or app not being visible should be implemented using platform‑specific Android services or jobs and then invoked from MAUI via dependency injection or platform code.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.