.NET MAUI: I want to fetch data from remote server even when the app is closed.

Dibyojyoti Majumder 0 Reputation points
2023-12-01T07:24:01.5166667+00:00

I have a mobile application which needs to download some data periodically from remote server. This should happen even when the application(android/ iOS) is not running in foreground or in background. Basically, I want the data to be downloaded from remote server even when the android/iOS application is closed/killed. Is it possible to achieve in .NET maui. If yes, then how ? Thanks.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,595 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,176 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 38,756 Reputation points Microsoft Vendor
    2023-12-04T05:21:13.72+00:00

    Hello,

    This is not feasible because the program cannot do anything when the program process is fully recycled. This is not a problem with MAUI, but the application management and security of Android and iOS.

    For Android and iOS, the official recommended best practice for downloading is to use service. You could increase the priority of the service to minimize the interruption of the download, but not when the program is not running.

    Android:

    Processes and app lifecycle

    A service process is one holding a Service that has been started with the startService() method. Though these processes are not directly visible to the user, they are generally doing things that the user cares about (such as background network data upload or download), so the system always keeps such processes running unless there is not enough memory to retain all foreground and visible processes. Services that have been running for a long time (such as 30 minutes or more) might be demoted in importance to let their process drop to the cached list. Processes that do need to be run over a long period can be created with setForeground. If it is a periodic process that requires strict time of execution, it can be scheduled through the AlarmManager. For more information, refer to Support for long-running workers. This helps avoid situations where long-running services that use excessive resources, for example, by leaking memory, prevent the system from delivering a good user experience.

    iOS:

    Introduction to Backgrounding in iOS.

    Register a Background Task - If an application needs to complete an important task, it can ask iOS not to interrupt the task when the application moves into the background. For example, an application might need to finish logging in a user, or finish downloading a large file.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments